summaryrefslogtreecommitdiff
path: root/Python/pystrtod.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-05-05 18:26:08 +0000
committerEric Smith <eric@trueblade.com>2009-05-05 18:26:08 +0000
commit20c6bb993afffa60e48b2f2d56515d5dbd8b8351 (patch)
tree0f46f0c90623a332939b915e34ade45146ac1c92 /Python/pystrtod.c
parenta383b6eefed90ceed252e43bbee2060ca25bca17 (diff)
downloadcpython-20c6bb993afffa60e48b2f2d56515d5dbd8b8351.tar.gz
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Diffstat (limited to 'Python/pystrtod.c')
-rw-r--r--Python/pystrtod.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 2be383442d..79f63e2603 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -660,16 +660,15 @@ _PyOS_double_to_string(char *buf, size_t buf_len, double val,
/* Supplied precision is unused, must be 0. */
if (precision != 0)
return;
+ /* The repr() precision (17 significant decimal digits) is the
+ minimal number that is guaranteed to have enough precision
+ so that if the number is read back in the exact same binary
+ value is recreated. This is true for IEEE floating point
+ by design, and also happens to work for all other modern
+ hardware. */
precision = 17;
format_code = 'g';
break;
- case 's': /* str format */
- /* Supplied precision is unused, must be 0. */
- if (precision != 0)
- return;
- precision = 12;
- format_code = 'g';
- break;
default:
assert(0);
return;