summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2008-04-19 18:51:48 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2008-04-19 18:51:48 (GMT)
commite941d97d123377c9e2c9f4cfec2e9827df0467c4 (patch)
treebff8904bbe7b9ea8d4c6b09fc6a84cb7e6ab1842 /Modules/mathmodule.c
parentc7bef374029a69719d8ba7f7d5ed9b056b2d0457 (diff)
downloadcpython-e941d97d123377c9e2c9f4cfec2e9827df0467c4.zip
cpython-e941d97d123377c9e2c9f4cfec2e9827df0467c4.tar.gz
cpython-e941d97d123377c9e2c9f4cfec2e9827df0467c4.tar.bz2
Additional tests for math.pow, and extra special-case
handling code in math.pow, in the hope of making all tests pass on the alpha Tru64 buildbot.
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 56b52fd..a78b698 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -513,6 +513,7 @@ math_pow(PyObject *self, PyObject *args)
{
PyObject *ox, *oy;
double r, x, y;
+ int y_is_odd;
if (! PyArg_UnpackTuple(args, "pow", 2, 2, &ox, &oy))
return NULL;
@@ -523,6 +524,16 @@ math_pow(PyObject *self, PyObject *args)
/* 1**x and x**0 return 1., even if x is a NaN or infinity. */
if (x == 1.0 || y == 0.0)
return PyFloat_FromDouble(1.);
+ /* inf ** (nonzero, non-NaN) is one of +-0, +-infinity */
+ if (Py_IS_INFINITY(x) && !Py_IS_NAN(y)) {
+ y_is_odd = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0;
+ if (y > 0.)
+ r = y_is_odd ? x : fabs(x);
+ else
+ r = y_is_odd ? copysign(0., x) : 0.;
+ return PyFloat_FromDouble(r);
+ }
+
errno = 0;
PyFPE_START_PROTECT("in math_pow", return 0);
r = pow(x, y);