summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-16 20:42:57 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-16 20:42:57 (GMT)
commitc13bcca2689c4bc08429e7a52e22e3d058f3b8ce (patch)
treec6640563748b8c466e79f91bb1c97a150a5a654b
parentfe58e3e22c187b21d5a2fbe5e03957442edfbb8c (diff)
downloadcpython-c13bcca2689c4bc08429e7a52e22e3d058f3b8ce.zip
cpython-c13bcca2689c4bc08429e7a52e22e3d058f3b8ce.tar.gz
cpython-c13bcca2689c4bc08429e7a52e22e3d058f3b8ce.tar.bz2
Test for negative # to the nonintegral float power here.
Expanded powi() in-line.
-rw-r--r--Objects/floatobject.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 74ef26e..cc0b98a 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -338,18 +338,6 @@ static double powu(x, n)
return r;
}
-static double powi(x, n)
- double x;
- long n;
-{
- if (n > 10000 || n < -10000)
- return pow(x, (double) n);
- else if (n > 0)
- return powu(x, n);
- else
- return 1./powu(x, -n);
-}
-
static object *
float_pow(v, w, z)
floatobject *v;
@@ -366,7 +354,7 @@ float_pow(v, w, z)
iv = v->ob_fval;
iw = ((floatobject *)w)->ob_fval;
intw = (long)iw;
- if (iw == intw) {
+ if (iw == intw && -10000 < intw && intw < 10000) {
/* Sort out special cases here instead of relying on pow() */
if (intw == 0) { /* x**0 is 1, even 0**0 */
if ((object *)z!=None) {
@@ -377,17 +365,26 @@ float_pow(v, w, z)
return newfloatobject(ix);
}
errno = 0;
- ix = powi(iv, intw);
+ if (intw > 0)
+ ix = powu(iv, intw);
+ else
+ ix = 1./powu(iv, -intw);
}
else {
/* Sort out special cases here instead of relying on pow() */
if (iv == 0.0) {
if (iw < 0.0) {
- err_setstr(ValueError, "0.0 to a negative power");
+ err_setstr(ValueError,
+ "0.0 to a negative power");
return NULL;
}
return newfloatobject(0.0);
}
+ if (iv < 0.0) {
+ err_setstr(ValueError,
+ "negative number to a float power");
+ return NULL;
+ }
errno = 0;
ix = pow(iv, iw);
}