diff Modules/mathmodule.c @ 46486:82d85a05923b legacy-trunk

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.
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 19 Apr 2008 18:51:48 +0000
parents 5bc7b20dc04a
children 648b4d01cccf
line wrap: on
line diff
--- a/Modules/mathmodule.c	Sat Apr 19 17:00:14 2008 +0000
+++ b/Modules/mathmodule.c	Sat Apr 19 18:51:48 2008 +0000
@@ -513,6 +513,7 @@
 {
 	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 @@
 	/* 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);