Mercurial > cpython-lru_cache-weakref
diff Python/pystrtod.c @ 53802:1d8f24d40c2c legacy-trunk
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.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Tue, 05 May 2009 18:26:08 +0000 |
| parents | 4f867f1494d5 |
| children | 38fda3a42c0b |
line wrap: on
line diff
--- a/Python/pystrtod.c Tue May 05 17:41:47 2009 +0000 +++ b/Python/pystrtod.c Tue May 05 18:26:08 2009 +0000 @@ -660,16 +660,15 @@ /* 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;
