[pypy-svn] pypy default: Remove limitation on long float formatting.

amauryfa commits-noreply at bitbucket.org
Wed Jan 26 00:15:50 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r41331:bd66c44b63eb
Date: 2011-01-26 00:19 +0100
http://bitbucket.org/pypy/pypy/changeset/bd66c44b63eb/

Log:	Remove limitation on long float formatting.

diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py
--- a/pypy/objspace/std/formatting.py
+++ b/pypy/objspace/std/formatting.py
@@ -3,7 +3,7 @@
 """
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.rarithmetic import (
-    ovfcheck, formatd_overflow, DTSF_ALT, isnan, isinf)
+    ovfcheck, formatd, DTSF_ALT, isnan, isinf)
 from pypy.interpreter.error import OperationError
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.rstring import StringBuilder, UnicodeBuilder
@@ -142,11 +142,7 @@
             flags = 0
             if self.f_alt:
                 flags |= DTSF_ALT
-            try:
-                r = formatd_overflow(x, char, prec, flags)
-            except OverflowError:
-                raise OperationError(space.w_OverflowError, space.wrap(
-                    "formatted float is too long (precision too large?)"))
+            r = formatd(x, char, prec, flags)
         self.std_wp_number(r)
 
     def std_wp_number(self, r, prefix=''):

diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -637,21 +637,6 @@
     else:
         return _formatd(x, code, precision, flags)
 
-formatd_max_length = 120
-
-def formatd_overflow(x, kind, precision, flags=0):
-    # 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+precision) or
-        (kind in 'fF' and formatd_max_length < 53+precision)):
-        raise OverflowError("formatted float is too long (precision too large?)")
-
-    return formatd(x, kind, precision, flags)
-
 def double_to_string(value, tp, precision, flags):
     if isnan(value):
         special = DIST_NAN
@@ -659,7 +644,7 @@
         special = DIST_INFINITY
     else:
         special = DIST_FINITE
-    result = formatd_overflow(value, tp, precision)
+    result = formatd(value, tp, precision, flags)
     return result, special
 
 # the 'float' C type

diff --git a/pypy/rlib/test/test_rarithmetic.py b/pypy/rlib/test/test_rarithmetic.py
--- a/pypy/rlib/test/test_rarithmetic.py
+++ b/pypy/rlib/test/test_rarithmetic.py
@@ -349,14 +349,20 @@
         res = self.ll_to_string(self.interpret(f, [1.1]))
         assert res == '1.1'
 
-    def test_formatd_overflow(self):
+    def test_formatd_huge(self):
+        def f(x):
+            return formatd(x, 'f', 1234, 0)
+        res = self.ll_to_string(self.interpret(f, [1.0]))
+        assert res == '1.' + 1234 * '0'
+
+    def test_formatd_F(self):
         from pypy.translator.c.test.test_genc import compile
-        from pypy.rlib.rarithmetic import formatd_overflow
+        from pypy.rlib.rarithmetic import formatd
 
         def func(x):
             # Test the %F format, which is not supported by
             # the Microsoft's msvcrt library.
-            return formatd_overflow(x, 'F', 4)
+            return formatd(x, 'F', 4)
 
         f = compile(func, [float])
         assert f(10/3.0) == '3.3333'
@@ -408,6 +414,9 @@
     def test_formatd_repr(self):
         skip('formatd is broken on ootype')
 
+    def test_formatd_huge(self):
+        skip('formatd is broken on ootype')
+
     def test_string_to_float(self):
         skip('string_to_float is broken on ootype')
 


More information about the Pypy-commit mailing list