Index: Include/pyport.h =================================================================== --- Include/pyport.h (revision 60144) +++ Include/pyport.h (working copy) @@ -475,7 +475,8 @@ * This isn't reliable. See Py_OVERFLOWED comments. * X is evaluated more than once. */ -#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64)) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || \ + (defined(__hpux) && defined(__ia64)) || defined(__APPLE__) #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM; #else #define _Py_SET_EDOM_FOR_NAN(X) ; Index: Modules/mathmodule.c =================================================================== --- Modules/mathmodule.c (revision 60144) +++ Modules/mathmodule.c (working copy) @@ -51,6 +51,8 @@ math_1(PyObject *arg, double (*func) (double)) { double x = PyFloat_AsDouble(arg); + if (Py_IS_NAN(x)) + return PyFloat_FromDouble(x); if (x == -1.0 && PyErr_Occurred()) return NULL; errno = 0;