[pypy-svn] pypy shorter-float-repr: Write a minus sign when the number is negative :-)

amauryfa commits-noreply at bitbucket.org
Fri Jan 21 00:08:24 CET 2011


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

Log:	Write a minus sign when the number is negative :-)

diff --git a/pypy/rpython/module/ll_dtoa.py b/pypy/rpython/module/ll_dtoa.py
--- a/pypy/rpython/module/ll_dtoa.py
+++ b/pypy/rpython/module/ll_dtoa.py
@@ -55,6 +55,10 @@
                 output_ptr = dg_dtoa(value, mode, precision,
                                      decpt_ptr, sign_ptr, end_ptr)
                 try:
+                    if sign_ptr[0] == 1:
+                        builder.append('-')
+                    elif flags & rarithmetic.DTSF_SIGN:
+                        builder.append('+')
                     buflen = (rffi.cast(rffi.LONG, end_ptr[0]) -
                               rffi.cast(rffi.LONG, output_ptr))
                     intpart = rffi.cast(lltype.Signed, decpt_ptr[0])

diff --git a/pypy/rpython/module/test/test_ll_dtoa.py b/pypy/rpython/module/test/test_ll_dtoa.py
--- a/pypy/rpython/module/test/test_ll_dtoa.py
+++ b/pypy/rpython/module/test/test_ll_dtoa.py
@@ -1,4 +1,4 @@
-from pypy.rpython.module.ll_dtoa import strtod, dtoa
+from pypy.rpython.module.ll_dtoa import strtod, dtoa, rarithmetic
 
 def test_strtod():
     assert strtod("12345") == 12345.0
@@ -9,6 +9,8 @@
 def test_dtoa():
     assert dtoa(3.47) == "3.47"
     assert dtoa(1.1) == "1.1"
+    assert dtoa(-1.1) == "-1.1"
+    assert dtoa(1.1, flags=rarithmetic.DTSF_SIGN) == "+1.1"
     assert dtoa(12.3577) == "12.3577"
     assert dtoa(10.0) == "10"
     assert dtoa(1.0e100) == "1" + "0" * 100


More information about the Pypy-commit mailing list