[pypy-svn] r48146 - in pypy/dist/pypy/translator/llvm: . test

rxe at codespeak.net rxe at codespeak.net
Mon Oct 29 12:13:12 CET 2007


Author: rxe
Date: Mon Oct 29 12:13:11 2007
New Revision: 48146

Modified:
   pypy/dist/pypy/translator/llvm/database.py
   pypy/dist/pypy/translator/llvm/test/test_lltype.py
Log:
test and fix for negative infinity floats, found with targetjsstandalone

Modified: pypy/dist/pypy/translator/llvm/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/database.py	(original)
+++ pypy/dist/pypy/translator/llvm/database.py	Mon Oct 29 12:13:11 2007
@@ -465,11 +465,9 @@
         return str(ord(value))
 
     def repr_float(self, type_, value):
-        repr = "%f" % value
-        # llvm requires a . when using e notation
-        if "e" in repr and "." not in repr:
-            repr = repr.replace("e", ".0e")
-        elif repr in ["inf", "nan"]:
+        from pypy.rlib.rarithmetic import isinf, isnan
+
+        if isinf(value) or isnan(value):
             # Need hex repr
             import struct
             packed = struct.pack("d", value)
@@ -477,6 +475,13 @@
                 packed = packed[::-1]
             
             repr = "0x" + "".join([("%02x" % ord(ii)) for ii in packed])
+        else:
+            repr = "%f" % value
+            
+            # llvm requires a . when using e notation
+            if "e" in repr and "." not in repr:
+                repr = repr.replace("e", ".0e")
+
         return repr
 
     def repr_address(self, type_, value):

Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lltype.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_lltype.py	Mon Oct 29 12:13:11 2007
@@ -216,8 +216,10 @@
     f = compile_function(struct_opaque, [])
     assert f() == struct_opaque()
 
-def test_floats():  #note: this is known to fail with llvm1.6 and llvm1.7cvs when not using gcc
+def test_floats():
     " test pbc of floats "
+    from pypy.rlib.rarithmetic import INFINITY, NAN
+
     if sys.maxint != 2**31-1:
         py.test.skip("WIP on 64 bit architectures")
     F = GcStruct("f",
@@ -226,19 +228,23 @@
                         ('f3', Float),
                         ('f4', Float),
                         ('f5', Float),
+                        ('f6', Float),
                         )
     floats = malloc(F)
     floats.f1 = 1.25
     floats.f2 = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.252984
     floats.f3 = float(29050000000000000000000000000000000000000000000000000000000000000000)
-    floats.f4 = 1e300 * 1e300
-    nan = floats.f5 = floats.f4/floats.f4
+    floats.f4 = INFINITY
+    nan = floats.f5 = NAN
+    floats.f6 = -INFINITY
+
     def floats_fn():
         res  = floats.f1 == 1.25
         res += floats.f2 > 1e100
         res += floats.f3 > 1e50        
         res += floats.f4 > 1e200
-        res += floats.f5 == nan
+        res += floats.f5 == NAN
+        res += floats.f4 < -1e200
         return res
     f = compile_function(floats_fn, [])
     assert f() == floats_fn()



More information about the Pypy-commit mailing list