]> granicus.if.org Git - python/commitdiff
Fix issue 3411: default float format spec fails on negative numbers.
authorEric Smith <eric@trueblade.com>
Sat, 19 Jul 2008 00:24:05 +0000 (00:24 +0000)
committerEric Smith <eric@trueblade.com>
Sat, 19 Jul 2008 00:24:05 +0000 (00:24 +0000)
Lib/test/test_types.py
Python/pystrtod.c

index 03f2ff88d3730528c78ebaccb26da8e9e7dcf3b2..10ad6346c4ee55a9384d690e48823debc0854cfd 100644 (file)
@@ -570,6 +570,12 @@ class TypesTests(unittest.TestCase):
         test(0.01, '', '0.01')
         test(0.01, 'g', '0.01')
 
+        # test for issue 3411
+        test(1.23, '1', '1.23')
+        test(-1.23, '1', '-1.23')
+        test(1.23, '1g', '1.23')
+        test(-1.23, '1g', '-1.23')
+
         test( 1.0, ' g', ' 1')
         test(-1.0, ' g', '-1')
         test( 1.0, '+g', '+1')
index 01c1c42770d3aa7d09230df2047346b1433ec00b..302e01298a445e3cb9f8c8477e4bb21b926529ec 100644 (file)
@@ -302,6 +302,10 @@ ensure_decimal_point(char* buffer, size_t buf_size)
 
        /* search for the first non-digit character */
        char *p = buffer;
+       if (*p == '-' || *p == '+')
+               /* Skip leading sign, if present.  I think this could only
+                  ever be '-', but it can't hurt to check for both. */
+               ++p;
        while (*p && isdigit(Py_CHARMASK(*p)))
                ++p;