[pypy-svn] r36280 - in pypy/dist/pypy/translator/c: . test
mwh at codespeak.net
mwh at codespeak.net
Mon Jan 8 16:32:25 CET 2007
Author: mwh
Date: Mon Jan 8 16:32:23 2007
New Revision: 36280
Modified:
pypy/dist/pypy/translator/c/node.py
pypy/dist/pypy/translator/c/primitive.py
pypy/dist/pypy/translator/c/test/test_genc.py
Log:
NaN support in genc.
testing on windows might be a good idea.
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Mon Jan 8 16:32:23 2007
@@ -10,7 +10,7 @@
from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
from pypy.translator.c.support import cdecl, forward_cdecl, somelettersfrom
from pypy.translator.c.support import c_char_array_constant
-from pypy.translator.c.primitive import PrimitiveType, isinf
+from pypy.translator.c.primitive import PrimitiveType, isinf, isnan
from pypy.translator.c import extfunc
@@ -572,7 +572,7 @@
node = db.getcontainernode(value._obj)
expr = 'NULL /*%s*/' % node.name
node.where_to_copy_me.append('&%s' % access_expr)
- elif typeOf(value) == Float and isinf(value):
+ elif typeOf(value) == Float and (isinf(value) or isnan(value)):
db.late_initializations.append(('%s' % access_expr, db.get(value)))
expr = '0.0 /* patched later by %sinfinity */' % (
'-+'[value > 0])
Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py (original)
+++ pypy/dist/pypy/translator/c/primitive.py Mon Jan 8 16:32:23 2007
@@ -71,12 +71,20 @@
def isinf(x):
return x != 0.0 and x / 2 == x
+# To get isnan, working x-platform and both on 2.3 and 2.4, is a
+# horror. I think this works (for reasons I don't really want to talk
+# about), and probably when implemented on top of pypy, too.
+def isnan(v):
+ return v != v*1.0 or (v == 1.0 and v == 2.0)
+
def name_float(value, db):
if isinf(value):
if value > 0:
return '(Py_HUGE_VAL)'
else:
return '(-Py_HUGE_VAL)'
+ elif isnan(value):
+ return '(Py_HUGE_VAL/Py_HUGE_VAL)'
else:
return repr(value)
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 Mon Jan 8 16:32:23 2007
@@ -248,6 +248,26 @@
res = f1(3)
assert res == 1.5
+def test_nan():
+ from pypy.translator.c.primitive import isnan, isinf
+ inf = 1e300 * 1e300
+ assert isinf(inf)
+ nan = inf/inf
+ assert isnan(nan)
+
+ l = [nan]
+ def f():
+ return nan
+ f1 = compile(f, [])
+ res = f1()
+ assert isnan(res)
+
+ def g(x):
+ return l[x]
+ g2 = compile(g, [int])
+ res = g2(0)
+ assert isnan(res)
+
def test_x():
class A:
pass
@@ -343,4 +363,3 @@
s = t.buildannotator().build_types(f, [])
rtyper = t.buildrtyper(type_system="lltype")
rtyper.specialize()
-
More information about the Pypy-commit
mailing list