]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix special cases in pow()
authorGuido van Rossum <guido@python.org>
Tue, 28 May 1991 21:57:39 +0000 (21:57 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 28 May 1991 21:57:39 +0000 (21:57 +0000)
Objects/floatobject.c

index 0549990a1b16de1d86355af3592f9b0d479d23f2..e2095d723cb29f5f48864a87916d2c82a9410924 100644 (file)
@@ -223,8 +223,20 @@ float_pow(v, w)
        }
        iv = v->ob_fval;
        iw = ((floatobject *)w)->ob_fval;
+       /* Sort out special cases here instead of relying on pow() */
        if (iw == 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;
        ix = pow(iv, iw);
        if (errno != 0) {