Skip to content

Commit 5afb5c6

Browse files
committed
Add link to math.fsum().
1 parent b525e18 commit 5afb5c6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Doc/tutorial/floatingpoint.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ Since the representation is exact, it is useful for reliably porting values
189189
across different versions of Python (platform independence) and exchanging
190190
data with other languages that support the same format (such as Java and C99).
191191

192+
Another helpful tool is the :func:`math.fsum` function which helps mitigate
193+
loss-of-precision during summation. It tracks "lost digits" as values are
194+
added onto a running total. That can make a difference in overall accuracy
195+
so that the errors do not accumulate to the point where they affect the
196+
final total:
197+
198+
>>> sum([0.1] * 10) == 1.0
199+
False
200+
>>> math.fsum([0.1] * 10) == 1.0
201+
True
192202

193203
.. _tut-fp-error:
194204

0 commit comments

Comments
 (0)