]> granicus.if.org Git - python/commitdiff
Add an example for math.fsum() and elaborate on the accurary note.
authorRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 05:48:05 +0000 (05:48 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 19 Feb 2009 05:48:05 +0000 (05:48 +0000)
Doc/library/math.rst

index ab39424373c916f0cc4d717bb46ff812f7c557b1..55e03bfa5574089cade2b994808e2d6155811660 100644 (file)
@@ -80,14 +80,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.
 
 
 .. function:: isinf(x)