[pypy-commit] pypy py3k: Ensure that repr(<some float>) is the same as str(<some float>).

Manuel Jacob noreply at buildbot.pypy.org
Sun Feb 17 23:07:33 CET 2013


Author: Manuel Jacob
Branch: py3k
Changeset: r61370:858eded385ad
Date: 2013-02-16 23:58 +0100
http://bitbucket.org/pypy/pypy/changeset/858eded385ad/

Log:	Ensure that repr(<some float>) is the same as str(<some float>).

diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -162,11 +162,14 @@
         s = "nan"
     return s
 
+#XXX short float repr?
+
 def repr__Float(space, w_float):
     return space.wrap(float2string(w_float.floatval, 'r', 0))
 
 def str__Float(space, w_float):
-    return space.wrap(float2string(w_float.floatval, 'g', DTSF_STR_PRECISION))
+    return space.wrap(float2string(w_float.floatval, 'r', 0))
+    #return space.wrap(float2string(w_float.floatval, 'g', DTSF_STR_PRECISION))
 
 def format__Float_ANY(space, w_float, w_spec):
     return newformat.run_formatter(space, w_spec, "format_float", w_float)
diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -837,3 +837,6 @@
         check(mod(0.0, -1.0), -0.0)
         check(mod(1e-100, -1.0), -1.0)
         check(mod(1.0, -1.0), -0.0)
+
+    def test_repr_str_eq(self):
+        assert repr(19 * 0.1) == str(19 * 0.1)


More information about the pypy-commit mailing list