[pypy-svn] r65633 - in pypy/branch/io-lang/pypy/lang/io: . test

david at codespeak.net david at codespeak.net
Sun Jun 7 11:50:24 CEST 2009


Author: david
Date: Sun Jun  7 11:50:22 2009
New Revision: 65633

Modified:
   pypy/branch/io-lang/pypy/lang/io/model.py
   pypy/branch/io-lang/pypy/lang/io/number.py
   pypy/branch/io-lang/pypy/lang/io/test/test_number.py
Log:
switched to the python representations of nan and infinity for Number

Modified: pypy/branch/io-lang/pypy/lang/io/model.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/model.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/model.py	Sun Jun  7 11:50:22 2009
@@ -46,16 +46,14 @@
         
 class W_Number(W_Object):
     """Number"""
-    def __init__(self, space, value, protos = None, nan=False, inf=False):
+    def __init__(self, space, value, protos = None):
         self.value = value
         if protos is None:
             pp = [space.w_number]
         else:
             pp = protos
         W_Object.__init__(self, space, pp) 
-        # TODO: operations on nan and inf instances
-        self.is_nan = nan
-        self.is_inf = inf
+
         
     def clone(self):
         cloned = W_Number(self.space, self.value)

Modified: pypy/branch/io-lang/pypy/lang/io/number.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/number.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/number.py	Sun Jun  7 11:50:22 2009
@@ -47,13 +47,13 @@
     try:
         value = dividend/float(divisor)
     except ZeroDivisionError, e:
-        value = 0
+        # XXX: TODO not sure if this is rpython
         if dividend == 0:
-            nan = True
+            value = float('nan')
         else:
-            inf = True
+            value = float('inf')
     finally:
-        return W_Number(space, value, nan=nan, inf=inf)
+        return W_Number(space, value)
     
 @register_method('Number', '*', unwrap_spec=[float, float])
 def w_number_multiply(space, a, b):

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_number.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_number.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_number.py	Sun Jun  7 11:50:22 2009
@@ -1,6 +1,8 @@
 from pypy.lang.io.parserhack import interpret
 from pypy.lang.io.model import W_Number
+from math import isnan, isinf
 import py
+
 def test_even_simpler():
     x, _ = interpret("2")
     assert x.value == 2
@@ -133,16 +135,12 @@
 def test_division_by_zero():
     inp = '3/0'
     res, _ = interpret(inp)
-    assert res.is_nan == False
-    assert res.is_inf == True
-    assert res.value == 0
+    assert isinf(res.value)
     
 def test_division_zero_by_zero():
     inp = '0/0'
     res, _ = interpret(inp)
-    assert res.is_nan == True
-    assert res.is_inf == False
-    assert res.value == 0
+    assert isnan(res.value)
     
 def test_multiply():
     inp = '6*7'



More information about the Pypy-commit mailing list