Kaydet (Commit) 7d854955 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Add an example for math.fsum() and elaborate on the accurary note.

üst f9bce83e
...@@ -87,14 +87,18 @@ Number-theoretic and representation functions ...@@ -87,14 +87,18 @@ Number-theoretic and representation functions
.. function:: fsum(iterable) .. function:: fsum(iterable)
Return an accurate floating point sum of values in the iterable. Avoids Return an accurate floating point sum of values in the iterable. Avoids
loss of precision by tracking multiple intermediate partial sums. The loss of precision by tracking multiple intermediate partial sums::
algorithm's accuracy depends on IEEE-754 arithmetic guarantees and the
typical case where the rounding mode is half-even. >>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
0.99999999999999989
.. note:: >>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
1.0
The accuracy of fsum() may be impaired on builds that use
extended precision addition and then double-round the results. 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 .. versionadded:: 2.6
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment