[pypy-svn] r47934 - in pypy/dist/pypy: rlib rlib/test translator/c

oscar at codespeak.net oscar at codespeak.net
Thu Oct 25 16:18:36 CEST 2007


Author: oscar
Date: Thu Oct 25 16:18:35 2007
New Revision: 47934

Modified:
   pypy/dist/pypy/rlib/rarithmetic.py
   pypy/dist/pypy/rlib/test/test_rarithmetic.py
   pypy/dist/pypy/translator/c/primitive.py
Log:
(cbolz, oscar) added INFINITY and NAN; added tests; moved isinf and isnan from c backend to rarithmetic

Modified: pypy/dist/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/dist/pypy/rlib/rarithmetic.py	(original)
+++ pypy/dist/pypy/rlib/rarithmetic.py	Thu Oct 25 16:18:35 2007
@@ -45,9 +45,18 @@
 LONG_MASK = _Ltest*2-1
 LONG_TEST = _Ltest
 
+INFINITY = 1e200 * 1e200
+NAN = INFINITY / INFINITY
+
 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 intmask(n):
     if isinstance(n, int):
         return int(n)   # possibly bool->int

Modified: pypy/dist/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rarithmetic.py	(original)
+++ pypy/dist/pypy/rlib/test/test_rarithmetic.py	Thu Oct 25 16:18:35 2007
@@ -331,3 +331,8 @@
 class TestOOtype(BaseTestRarithmetic, OORtypeMixin):
     pass
 
+def test_isinf():
+    assert isinf(INFINITY)
+
+def test_isnan():
+    assert isnan(NAN)

Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py	(original)
+++ pypy/dist/pypy/translator/c/primitive.py	Thu Oct 25 16:18:35 2007
@@ -1,7 +1,7 @@
 import sys
 from pypy.rlib.objectmodel import Symbolic, ComputedIntSymbolic
 from pypy.rlib.objectmodel import CDefinedIntSymbolic
-from pypy.rlib.rarithmetic import r_longlong
+from pypy.rlib.rarithmetic import r_longlong, isinf, isnan
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.rpython.lltypesystem import rffi
 from pypy.rpython.lltypesystem.llmemory import Address, \
@@ -81,15 +81,6 @@
     else:
         return '%dLL' % value
 
-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:



More information about the Pypy-commit mailing list