diff Modules/mathmodule.c @ 46499:80b16595e462 legacy-trunk

FreeBSD doesn't follow C99 for modf(inf); so add explicit special-value handling to math.modf code.
author Mark Dickinson <dickinsm@gmail.com>
date Sun, 20 Apr 2008 01:39:24 +0000
parents 648b4d01cccf
children a20def0101de
line wrap: on
line diff
--- a/Modules/mathmodule.c	Sun Apr 20 01:22:30 2008 +0000
+++ b/Modules/mathmodule.c	Sun Apr 20 01:39:24 2008 +0000
@@ -341,6 +341,15 @@
 	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);