diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-04-20 01:39:24 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-04-20 01:39:24 (GMT) |
commit | b2f70902395a56fce14f47b685eb4966ec09257e (patch) | |
tree | e5ca2294ee08e44f43f9211dc580d865740229e3 /Modules | |
parent | 9f99d705138ddbea874ab41adc52becc7d9a02d5 (diff) | |
download | cpython-b2f70902395a56fce14f47b685eb4966ec09257e.zip cpython-b2f70902395a56fce14f47b685eb4966ec09257e.tar.gz cpython-b2f70902395a56fce14f47b685eb4966ec09257e.tar.bz2 |
FreeBSD doesn't follow C99 for modf(inf); so add explicit
special-value handling to math.modf code.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/mathmodule.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index bb97a2c..0e91f8f 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -341,6 +341,15 @@ math_modf(PyObject *self, PyObject *arg) double y, x = PyFloat_AsDouble(arg); if (x == -1.0 && PyErr_Occurred()) return NULL; + /* some platforms don't do the right thing for NaNs and + infinities, so we take care of special cases directly. */ + if (!Py_IS_FINITE(x)) { + if (Py_IS_INFINITY(x)) + return Py_BuildValue("(dd)", copysign(0., x), x); + else if (Py_IS_NAN(x)) + return Py_BuildValue("(dd)", x, x); + } + errno = 0; PyFPE_START_PROTECT("in math_modf", return 0); x = modf(x, &y); |