diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-04-19 19:41:52 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-04-19 19:41:52 (GMT) |
commit | a1293eb65f2237c3783a9bf9ba9ff5557cd384b0 (patch) | |
tree | 7cd915f326392c7450821fa4fe4f73f93dc05847 /Modules/mathmodule.c | |
parent | 53be57e8f894a40e8eaf1f7d0a6c3e0ff806ebb2 (diff) | |
download | cpython-a1293eb65f2237c3783a9bf9ba9ff5557cd384b0.zip cpython-a1293eb65f2237c3783a9bf9ba9ff5557cd384b0.tar.gz cpython-a1293eb65f2237c3783a9bf9ba9ff5557cd384b0.tar.bz2 |
Additional special-case handling for math.pow.
Windows/VS2008 doesn't like (-1)**(+-inf).
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r-- | Modules/mathmodule.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index a78b698..bb97a2c 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -521,9 +521,19 @@ math_pow(PyObject *self, PyObject *args) y = PyFloat_AsDouble(oy); if ((x == -1.0 || y == -1.0) && PyErr_Occurred()) return NULL; - /* 1**x and x**0 return 1., even if x is a NaN or infinity. */ - if (x == 1.0 || y == 0.0) + + /* deal directly with various special cases, to cope with problems on + various platforms whose semantics don't exactly match C99 */ + + /* 1**x, x**0, and (-1)**(+-infinity) return 1., even if x is NaN or + an infinity. */ + if (x == 1. || y == 0. || (x == -1. && Py_IS_INFINITY(y))) return PyFloat_FromDouble(1.); + /* otherwise, return a NaN if either input was a NaN */ + if (Py_IS_NAN(x)) + return PyFloat_FromDouble(x); + if (Py_IS_NAN(y)) + return PyFloat_FromDouble(y); /* 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; @@ -539,10 +549,7 @@ math_pow(PyObject *self, PyObject *args) r = pow(x, y); PyFPE_END_PROTECT(r); if (Py_IS_NAN(r)) { - if (!Py_IS_NAN(x) && !Py_IS_NAN(y)) - errno = EDOM; - else - errno = 0; + errno = EDOM; } /* an infinite result arises either from: |