[pypy-svn] r40620 - in pypy/dist/pypy/rpython: . test

rxe at codespeak.net rxe at codespeak.net
Fri Mar 16 22:41:28 CET 2007


Author: rxe
Date: Fri Mar 16 22:41:24 2007
New Revision: 40620

Modified:
   pypy/dist/pypy/rpython/rfloat.py
   pypy/dist/pypy/rpython/test/test_rfloat.py
Log:
allow longlong, and the rest, to convert to float constants

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Fri Mar 16 22:41:24 2007
@@ -9,6 +9,8 @@
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
 from pypy.rpython.rmodel import log
 
+from pypy.rlib.rarithmetic import base_int
+
 import math
 
 class __extend__(annmodel.SomeFloat):
@@ -104,7 +106,7 @@
 class __extend__(FloatRepr):
 
     def convert_const(self, value):
-        if not isinstance(value, (int, float)):  # can be bool too
+        if not isinstance(value, (int, base_int, float)):  # can be bool too
             raise TyperError("not a float: %r" % (value,))
         return float(value)
 

Modified: pypy/dist/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rfloat.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rfloat.py	Fri Mar 16 22:41:24 2007
@@ -94,6 +94,13 @@
         res = self.interpret(fn, [-9])
         assert res == 0.5 * ((sys.maxint+1)*2 - 9)
 
+    def test_float_constant_conversions(self):
+        DIV = r_longlong(10 ** 10)
+        def fn():
+            return 420000000000.0 / DIV
+
+        res = self.interpret(fn, [])
+        assert res == 42.0
 
 class TestLLtype(BaseTestRfloat, LLRtypeMixin):
 



More information about the Pypy-commit mailing list