]> granicus.if.org Git - python/commitdiff
FreeBSD doesn't follow C99 for modf(inf); so add explicit
authorMark Dickinson <dickinsm@gmail.com>
Sun, 20 Apr 2008 01:39:24 +0000 (01:39 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 20 Apr 2008 01:39:24 +0000 (01:39 +0000)
special-value handling to math.modf code.

Modules/mathmodule.c

index bb97a2c1023f15b1fd9e975ea7c44ed8245e6087..0e91f8fd6a48604ca59673b3038821342a30b00c 100644 (file)
@@ -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);