summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-05-28 21:57:39 (GMT)
committerGuido van Rossum <guido@python.org>1991-05-28 21:57:39 (GMT)
commit70d934601f743afe0f9a75fef95d6c3e65ec9bfd (patch)
tree49c4d5c007357d6cf9798e7c40d76825a96cc760
parent4b9cf8eed98f6a2f35531921e92df8cc07d703d4 (diff)
downloadcpython-70d934601f743afe0f9a75fef95d6c3e65ec9bfd.zip
cpython-70d934601f743afe0f9a75fef95d6c3e65ec9bfd.tar.gz
cpython-70d934601f743afe0f9a75fef95d6c3e65ec9bfd.tar.bz2
Fix special cases in pow()
-rw-r--r--Objects/floatobject.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 0549990..e2095d7 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -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) {