[pypy-commit] pypy win32-cleanup2: fix for float('nan') returning -NAN, Microsoft should try to adhere to standards

mattip noreply at buildbot.pypy.org
Sun Apr 8 00:46:01 CEST 2012


Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54241:da56cef5777d
Date: 2012-04-08 01:44 +0300
http://bitbucket.org/pypy/pypy/changeset/da56cef5777d/

Log:	fix for float('nan') returning -NAN, Microsoft should try to adhere
	to standards

diff --git a/pypy/translator/c/primitive.py b/pypy/translator/c/primitive.py
--- a/pypy/translator/c/primitive.py
+++ b/pypy/translator/c/primitive.py
@@ -11,6 +11,7 @@
      GCHeaderOffset, GCREF, AddressAsInt
 from pypy.rpython.lltypesystem.llarena import RoundedUpForAllocation
 from pypy.translator.c.support import cdecl, barebonearray
+from pypy.translator.platform import platform as target_platform
 
 # ____________________________________________________________
 #
@@ -98,11 +99,19 @@
     else:
         return '%dLL' % value
 
-def is_positive_nan(value):
-    # bah.  we don't have math.copysign() if we're running Python 2.5
-    import struct
-    c = struct.pack("!d", value)[0]
-    return {'\x7f': True, '\xff': False}[c]
+if target_platform.name == 'msvc':
+    def is_positive_nan(value):
+        # Microsoft decided that NAN should have the sign bit set,
+        # so the values are reversed!
+        import struct
+        c = struct.pack("!d", value)[0]
+        return {'\x7f': False, '\xff': True}[c]
+else:
+    def is_positive_nan(value):
+        # bah.  we don't have math.copysign() if we're running Python 2.5
+        import struct
+        c = struct.pack("!d", value)[0]
+        return {'\x7f': True, '\xff': False}[c]
 
 def name_float(value, db):
     if isinf(value):


More information about the pypy-commit mailing list