[Python-checkins] r62413 - python/trunk/Modules/mathmodule.c

mark.dickinson python-checkins at python.org
Sun Apr 20 03:39:24 CEST 2008


Author: mark.dickinson
Date: Sun Apr 20 03:39:24 2008
New Revision: 62413

Log:
FreeBSD doesn't follow C99 for modf(inf); so add explicit
special-value handling to math.modf code.


Modified:
   python/trunk/Modules/mathmodule.c

Modified: python/trunk/Modules/mathmodule.c
==============================================================================
--- python/trunk/Modules/mathmodule.c	(original)
+++ python/trunk/Modules/mathmodule.c	Sun Apr 20 03:39:24 2008
@@ -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);


More information about the Python-checkins mailing list