[pypy-svn] r8487 - in pypy/dist/pypy/objspace/std: . test

mwh at codespeak.net mwh at codespeak.net
Sun Jan 23 14:33:39 CET 2005


Author: mwh
Date: Sun Jan 23 14:33:39 2005
New Revision: 8487

Modified:
   pypy/dist/pypy/objspace/std/longobject.py
   pypy/dist/pypy/objspace/std/test/test_floatobject.py
Log:
Deal with overflow in long->float conversion.


Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py	(original)
+++ pypy/dist/pypy/objspace/std/longobject.py	Sun Jan 23 14:33:39 2005
@@ -39,7 +39,11 @@
         return w_value   # 9999999999999L.__int__() == 9999999999999L
 
 def float__Long(space, w_longobj):
-    return space.newfloat(float(w_longobj.longval))
+    try:
+        return space.newfloat(float(w_longobj.longval))
+    except OverflowError:
+        raise OperationError(space.w_OverflowError,
+                             space.wrap("long int too large to convert to float"))
 
 def long__Float(space, w_floatobj):
     return W_LongObject(space, long(w_floatobj.floatval))

Modified: pypy/dist/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_floatobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_floatobject.py	Sun Jan 23 14:33:39 2005
@@ -53,6 +53,12 @@
     def test_float_string(self):
         assert 42.0 == float("42")
 
+    def test_float_long(self):
+        assert 42.0 == float(42L)
+        assert 10000000000.0 == float(10000000000L)
+        raises(OverflowError, float, 10**400)
+        
+        
     def test_round(self):
         assert 1.0 == round(1.0)
         assert 1.0 == round(1.1)



More information about the Pypy-commit mailing list