diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-04-16 19:52:09 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-04-16 19:52:09 (GMT) |
commit | b08a53a99def3fa949643974f713b5b189e21bc7 (patch) | |
tree | 6f7663d510099fd7acfa328ae5a5c88e3eddb1a7 /Misc | |
parent | 579b65c2d695eb468fb97568ff7d2ad9d261b2b3 (diff) | |
download | cpython-b08a53a99def3fa949643974f713b5b189e21bc7.zip cpython-b08a53a99def3fa949643974f713b5b189e21bc7.tar.gz cpython-b08a53a99def3fa949643974f713b5b189e21bc7.tar.bz2 |
Issue #1580: use short float repr where possible.
- incorporate and adapt David Gay's dtoa and strtod
into the Python core
- on platforms where we can use Gay's code (almost
all!), repr(float) is based on the shortest
sequence of decimal digits that rounds correctly.
- add sys.float_repr_style attribute to indicate
whether we're using Gay's code or not
- add autoconf magic to detect and enable SSE2
instructions on x86/gcc
- slight change to repr and str: repr switches
to exponential notation at 1e16 instead of
1e17, str switches at 1e11 instead of 1e12
Diffstat (limited to 'Misc')
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 39 |
2 files changed, 40 insertions, 0 deletions
@@ -160,6 +160,7 @@ Scott David Daniels Ben Darnell Jonathan Dasteel John DeGood +Ned Deily Vincent Delft Arnaud Delobelle Erik Demaine @@ -12,6 +12,45 @@ What's New in Python 3.1 beta 1? Core and Builtins ----------------- +- The repr function switches to exponential notation at 1e16, not 1e17 + as it did before. This change applies to both 'short' and legacy + float repr styles. For the new repr style, it avoids misleading + output in some cases: an example is repr(2e16+8), which gives + '2.000000000000001e+16'; without this change it would have produced + '20000000000000010.0' instead. + +- Similarly, the str function switches to exponential notation at + 1e11, not 1e12. This avoids printing 13 significant digits in + situations where only 12 of them are correct. Example problem + value: str(1e11 + 0.5). (This minor issue has existed in 2.x for a + long time.) + +- On x86, SSE2 instructions for floating-point are automatically + detected and, where possible, enabled on platforms using the gcc + compiler. As a consequence, some arithmetic operations may have + different (more accurate!) results on some platforms, and + cross-platform consistency of Python arithmetic should be improved. + This applies particularly to Linux/x86. + +- Issue #1580: On most platforms, use a 'short' float repr: for a + finite float x, repr(x) now outputs a string based on the shortest + sequence of decimal digits that rounds to x. Previous behaviour was + to output 17 significant digits and then strip trailing zeros. + + There's a new sys attribute sys.float_repr_style, which takes + the value 'short' to indicate that we're using short float repr, + and 'legacy' if the short float repr isn't available for one + reason or another. + + The float repr change involves incorporating David Gay's 'perfect + rounding' code into the Python core (it's in Python/dtoa.c). As a + secondary consequence, all string-to-float and float-to-string + conversions (including all float formatting operations) will be + correctly rounded on these platforms. + + See issue 1580 discussions for details of platforms for which + this change does not apply. + - Issue #5759: float() didn't call __float__ on str subclasses. - The string.maketrans() function is deprecated; there is a new static method |