[pypy-svn] r61445 - in pypy/trunk/pypy/rlib: . test

afa at codespeak.net afa at codespeak.net
Thu Jan 29 13:56:03 CET 2009


Author: afa
Date: Thu Jan 29 13:56:02 2009
New Revision: 61445

Modified:
   pypy/trunk/pypy/rlib/rarithmetic.py
   pypy/trunk/pypy/rlib/test/test_rarithmetic.py
Log:
"%F" format used to return '?.??' on windows.
A test and a fix.


Modified: pypy/trunk/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/rarithmetic.py	(original)
+++ pypy/trunk/pypy/rlib/rarithmetic.py	Thu Jan 29 13:56:02 2009
@@ -442,6 +442,12 @@
     return fmt % (x,)
 
 def formatd_overflow(alt, prec, kind, x):
+    # msvcrt does not support the %F format.
+    # OTOH %F and %f only differ for 'inf' or 'nan' numbers
+    # which are already handled elsewhere
+    if kind == 'F':
+        kind = 'f'
+
     if ((kind in 'gG' and formatd_max_length <= 10+prec) or
         (kind in 'fF' and formatd_max_length <= 53+prec)):
         raise OverflowError("formatted float is too long (precision too large?)")

Modified: pypy/trunk/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rarithmetic.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_rarithmetic.py	Thu Jan 29 13:56:02 2009
@@ -323,6 +323,18 @@
         res = self.ll_to_string(self.interpret(f, [10/3.0]))
         assert res == '3.33'
 
+    def test_formatd_overflow(self):
+        from pypy.translator.c.test.test_genc import compile
+        from pypy.rlib.rarithmetic import formatd_overflow
+
+        def func(x):
+            # Test the %F format, which is not supported by
+            # the Microsoft's msvcrt library.
+            return formatd_overflow(0, 4, 'F', x)
+
+        f = compile(func, [float])
+        assert f(10/3.0) == '3.3333'
+
     def test_parts_to_float(self):
         from pypy.rlib.rarithmetic import parts_to_float, break_up_float
         def f(x):



More information about the Pypy-commit mailing list