[pypy-svn] r15384 - in pypy/dist/pypy/translator/c: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Jul 29 23:07:13 CEST 2005
Author: arigo
Date: Fri Jul 29 23:07:10 2005
New Revision: 15384
Modified:
pypy/dist/pypy/translator/c/primitive.py
pypy/dist/pypy/translator/c/test/test_genc.py
Log:
Support for constant float infinites.
Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py (original)
+++ pypy/dist/pypy/translator/c/primitive.py Fri Jul 29 23:07:10 2005
@@ -15,8 +15,17 @@
assert value >= 0
return '%dUL' % value
+def isinf(x):
+ return x != 0.0 and x / 2 == x
+
def name_float(value):
- return repr(value)
+ if isinf(value):
+ if value > 0:
+ return '1E9999999'
+ else:
+ return '-1E9999999'
+ else:
+ return repr(value)
def name_char(value):
assert type(value) is str and len(value) == 1
Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py Fri Jul 29 23:07:10 2005
@@ -199,3 +199,13 @@
f1 = compile(fn, [int])
res = f1(42)
assert res == 42
+
+def test_infinite_float():
+ x = 1.0
+ while x != x / 2:
+ x *= 3.1416
+ def fn():
+ return x
+ f1 = compile(fn, [])
+ res = f1()
+ assert res > 0 and res == res / 2
More information about the Pypy-commit
mailing list