[pypy-svn] r16003 - in pypy/dist/pypy/translator/llvm2: . test
rxe at codespeak.net
rxe at codespeak.net
Fri Aug 12 13:29:57 CEST 2005
Author: rxe
Date: Fri Aug 12 13:29:54 2005
New Revision: 16003
Modified:
pypy/dist/pypy/translator/llvm2/database.py
pypy/dist/pypy/translator/llvm2/test/test_lltype.py
Log:
Special cases for float reprs. For nan and inf, not sure totally right, need
to speak to the llvm guys.
Modified: pypy/dist/pypy/translator/llvm2/database.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/database.py (original)
+++ pypy/dist/pypy/translator/llvm2/database.py Fri Aug 12 13:29:54 2005
@@ -349,14 +349,27 @@
# __________________________________________________________
# Primitive stuff
+ def float_to_str(self, 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"]:
+ # Need hex repr
+ import struct
+ packed = struct.pack("d", value)
+ repr = "0x" + "".join([("%02x" % ord(ii)) for ii in packed])
+ return repr
+
def primitive_to_str(self, type_, value):
- #XXX Need to watch for special float values (inf, 2E200)
if type_ is lltype.Bool:
repr = str(value).lower() #False --> false
elif type_ is lltype.Char:
repr = str(ord(value))
elif type_ is lltype.UniChar:
repr = str(ord(value))
+ elif type_ is lltype.Float:
+ repr = self.float_to_str(value)
else:
repr = str(value)
return repr
Modified: pypy/dist/pypy/translator/llvm2/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_lltype.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_lltype.py Fri Aug 12 13:29:54 2005
@@ -213,3 +213,31 @@
return s.a
f = compile_function(array_constant, [])
assert f() == array_constant()
+
+def test_floats():
+ " test pbc of floats "
+ F = lltype.GcStruct("f",
+ ('f1', lltype.Float),
+ ('f2', lltype.Float),
+ ('f3', lltype.Float),
+ ('f4', lltype.Float),
+ ('f5', lltype.Float),
+ )
+ floats = lltype.malloc(F)
+ floats.f1 = 1.25
+ floats.f2 = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.252984
+ floats.f3 = float(29050000000000000000000000000000000000000000000000000000000000000000)
+ floats.f4 = float("inf")
+ floats.f5 = float("nan")
+ f = float("nan")
+ def floats_fn():
+ res = floats.f1 == 1.25
+ res += floats.f2 > 1e100
+ res += floats.f3 > 1e50
+ # XXX Need to find out more about these in llvm
+ #res += floats.f4 > 1e200
+ #res += floats.f5 == f
+ return res
+
+ f = compile_function(floats_fn, [])
+ assert f() == floats_fn()
More information about the Pypy-commit
mailing list