[pypy-svn] pypy shorter-float-repr: Plug our implementation of strtod

amauryfa commits-noreply at bitbucket.org
Fri Jan 21 19:11:37 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: shorter-float-repr
Changeset: r41174:aeaaf60cca62
Date: 2011-01-21 18:35 +0100
http://bitbucket.org/pypy/pypy/changeset/aeaaf60cca62/

Log:	Plug our implementation of strtod

diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -518,6 +518,10 @@
 
 
 def string_to_float(s):
+    if USE_SHORT_FLOAT_REPR:
+        from pypy.rlib.rdtoa import strtod
+        return strtod(s)
+
     sign, before_point, after_point, exponent = break_up_float(s)
 
     if not before_point and not after_point:

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
@@ -376,6 +376,18 @@
         res = self.interpret(f, [1])
         assert res == 1e-100
 
+    def test_string_to_float(self):
+        from pypy.rlib.rarithmetic import string_to_float
+        def func(x):
+            if x == 0:
+                s = '1e23'
+            else:
+                s = '-1e23'
+            return string_to_float(s)
+
+        assert self.interpret(func, [0]) == 1e23
+        assert self.interpret(func, [1]) == -1e23
+
     def test_compare_singlefloat_crashes(self):
         from pypy.rlib.rarithmetic import r_singlefloat
         from pypy.rpython.error import MissingRTypeOperation
@@ -396,6 +408,9 @@
     def test_formatd_repr(self):
         skip('formatd is broken on ootype')
 
+    def test_string_to_float(self):
+        skip('string_to_float is broken on ootype')
+
 def test_isinf():
     assert isinf(INFINITY)
 


More information about the Pypy-commit mailing list