mattip <matti.pi...@gmail.com> added the comment: You are correct, the patch should use fabs I would go with a standard, cross-platform definition of Py_NAN so that pickled objects could be opened by other platforms. Would this patch be better? It's more complicated as I needed to cast the repr of Py_NAN to a unsigned char[]. It passes the tests in test.test_math and handles the copysign in a more intuitive way
>>> math.copysign(1., float('nan')) => 1. on win32, microsoft compiler diff -r efeca6ff2751 Include/pymath.h --- a/Include/pymath.h Thu Apr 05 22:51:00 2012 +0200 +++ b/Include/pymath.h Sun Apr 08 22:20:16 2012 +0300 @@ -152,8 +152,13 @@ * doesn't support NaNs. */ #if !defined(Py_NAN) && !defined(Py_NO_NAN) +#if DBL_MANT_DIG == 53 /* ieee 754 doubles */ +extern double * _Py_NAN; +#define Py_NAN (*_Py_NAN) +#else #define Py_NAN (Py_HUGE_VAL * 0.) #endif +#endif /* Py_OVERFLOWED(X) * Return 1 iff a libm function overflowed. Set errno to 0 before calling diff -r efeca6ff2751 Modules/_math.c --- a/Modules/_math.c Thu Apr 05 22:51:00 2012 +0200 +++ b/Modules/_math.c Sun Apr 08 22:20:16 2012 +0300 @@ -24,6 +24,10 @@ static const double two_pow_p28 = 268435456.0; /* 2**28 */ static const double zero = 0.0; +#if DBL_MANT_DIG == 53 /* ieee 754 doubles */ +static const unsigned char _Py_NAN_as_char[8] = {0, 0, 0, 0, 0, 0, 0xf8, 0x7f}; +extern double * _Py_NAN = (double *)(_Py_NAN_as_char); +#endif /* acosh(x) * Method : * Based on ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14521> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com