diff options
author | Raymond Hettinger <python@rcn.com> | 2009-02-19 05:51:41 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-02-19 05:51:41 (GMT) |
commit | 7d854955e15f17e6bfb29890ac8fd7919b75d097 (patch) | |
tree | 143285e01c3410f4f9ac1302ace487c05a200706 | |
parent | f9bce83e71c07ccd7b0ae1a75ea6912f0023b802 (diff) | |
download | cpython-7d854955e15f17e6bfb29890ac8fd7919b75d097.zip cpython-7d854955e15f17e6bfb29890ac8fd7919b75d097.tar.gz cpython-7d854955e15f17e6bfb29890ac8fd7919b75d097.tar.bz2 |
Add an example for math.fsum() and elaborate on the accurary note.
-rw-r--r-- | Doc/library/math.rst | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Doc/library/math.rst b/Doc/library/math.rst index b33c597..4ecd14e 100644 --- a/Doc/library/math.rst +++ b/Doc/library/math.rst @@ -87,14 +87,18 @@ Number-theoretic and representation functions .. function:: fsum(iterable) Return an accurate floating point sum of values in the iterable. Avoids - loss of precision by tracking multiple intermediate partial sums. The - algorithm's accuracy depends on IEEE-754 arithmetic guarantees and the - typical case where the rounding mode is half-even. - - .. note:: - - The accuracy of fsum() may be impaired on builds that use - extended precision addition and then double-round the results. + loss of precision by tracking multiple intermediate partial sums:: + + >>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) + 0.99999999999999989 + >>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1]) + 1.0 + + The algorithm's accuracy depends on IEEE-754 arithmetic guarantees and the + typical case where the rounding mode is half-even. On some non-Windows + builds, the underlying C library uses extended precision addition and may + occasionally double-round an intermediate sum causing it to be off in its + least significant bit. .. versionadded:: 2.6 |