mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
Fix special cases in pow()
This commit is contained in:
parent
4b9cf8eed9
commit
70d934601f
1 changed files with 12 additions and 0 deletions
|
@ -223,8 +223,20 @@ float_pow(v, w)
|
||||||
}
|
}
|
||||||
iv = v->ob_fval;
|
iv = v->ob_fval;
|
||||||
iw = ((floatobject *)w)->ob_fval;
|
iw = ((floatobject *)w)->ob_fval;
|
||||||
|
/* Sort out special cases here instead of relying on pow() */
|
||||||
if (iw == 0.0)
|
if (iw == 0.0)
|
||||||
return newfloatobject(1.0); /* x**0 is 1, even 0**0 */
|
return newfloatobject(1.0); /* x**0 is 1, even 0**0 */
|
||||||
|
if (iv == 0.0) {
|
||||||
|
if (iw < 0.0) {
|
||||||
|
err_setstr(RuntimeError, "0.0 to the negative power");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return newfloatobject(0.0);
|
||||||
|
}
|
||||||
|
if (iv < 0.0) {
|
||||||
|
err_setstr(RuntimeError, "negative float to float power");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ix = pow(iv, iw);
|
ix = pow(iv, iw);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue