Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ad79e8

Browse files
committed
Merged revisions 65125 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r65125 | eric.smith | 2008-07-18 20:24:05 -0400 (Fri, 18 Jul 2008) | 1 line Fix issue 3411: default float format spec fails on negative numbers. ........
1 parent 32480b0 commit 2ad79e8

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,12 @@ def test(f, format_spec, result):
497497
test(0.01, '', '0.01')
498498
test(0.01, 'g', '0.01')
499499

500+
# test for issue 3411
501+
test(1.23, '1', '1.23')
502+
test(-1.23, '1', '-1.23')
503+
test(1.23, '1g', '1.23')
504+
test(-1.23, '1g', '-1.23')
505+
500506
test( 1.0, ' g', ' 1')
501507
test(-1.0, ' g', '-1')
502508
test( 1.0, '+g', '+1')

Python/pystrtod.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ ensure_decimal_point(char* buffer, size_t buf_size)
302302

303303
/* search for the first non-digit character */
304304
char *p = buffer;
305+
if (*p == '-' || *p == '+')
306+
/* Skip leading sign, if present. I think this could only
307+
ever be '-', but it can't hurt to check for both. */
308+
++p;
305309
while (*p && isdigit(Py_CHARMASK(*p)))
306310
++p;
307311

0 commit comments

Comments
 (0)