This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hniksic
Recipients hniksic
Date 2014-04-07.10:02:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396864952.24.0.891595123462.issue21167@psf.upfronthosting.co.za>
In-reply-to
Content
On a Python compiled with Intel C compiler, float('nan') returns 0.0. This behavior can be reproduced with icc versions 11 and 12.

The definition of Py_NAN in include/pymath.h expects `HUGE_VAL * 0.0` to compile to a NaN value on IEEE754 platforms:

/* Py_NAN
 * A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or
 * INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform
 * doesn't support NaNs.
 */
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
#define Py_NAN (Py_HUGE_VAL * 0.)
#endif

I don't have a copy of the standard, but a simple test shows that the above does not hold for icc. When compiled with icc without any flags, the following program outputs "inf 0.000000" instead of the expected "inf nan":

#include <stdio.h>
#include <math.h>

int main()
{
  double inf = HUGE_VAL;
  double nan = HUGE_VAL * 0;
  printf("%f %f\n", inf, nan);
  return 0;
}

Compiling the same program with gcc yields the expected output of "inf nan".

This issue can be fixed (or worked around, if it's an icc bug) by using a different definition of Py_NAN. On icc, defining Py_NAN as `Py_HUGE_VAL / Py_HUGE_VAL` produces the intended effect. If this is considered suboptimal on other compilers, the definition can be conditionally compiled for icc only.

The attached patch fixes the issue, taking the conservative approach of only modifying the icc definition of Py_NAN.
History
Date User Action Args
2014-04-07 10:02:32hniksicsetrecipients: + hniksic
2014-04-07 10:02:32hniksicsetmessageid: <1396864952.24.0.891595123462.issue21167@psf.upfronthosting.co.za>
2014-04-07 10:02:32hniksiclinkissue21167 messages
2014-04-07 10:02:31hniksiccreate