summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-04-26 22:01:46 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-04-26 22:01:46 (GMT)
commit5afb5c6630540f2b4fb314a9a7c5ea9692e0b0c0 (patch)
treef962885f2732b93a1c1e55000c6aeccc78562eea /Doc/tutorial
parentb525e18500885731f958bd4a0114f26cea336500 (diff)
downloadcpython-5afb5c6630540f2b4fb314a9a7c5ea9692e0b0c0.zip
cpython-5afb5c6630540f2b4fb314a9a7c5ea9692e0b0c0.tar.gz
cpython-5afb5c6630540f2b4fb314a9a7c5ea9692e0b0c0.tar.bz2
Add link to math.fsum().
Diffstat (limited to 'Doc/tutorial')
-rw-r--r--Doc/tutorial/floatingpoint.rst10
1 files changed, 10 insertions, 0 deletions
diff --git a/Doc/tutorial/floatingpoint.rst b/Doc/tutorial/floatingpoint.rst
index 98e299d..a8a4202 100644
--- a/Doc/tutorial/floatingpoint.rst
+++ b/Doc/tutorial/floatingpoint.rst
@@ -189,6 +189,16 @@ Since the representation is exact, it is useful for reliably porting values
across different versions of Python (platform independence) and exchanging
data with other languages that support the same format (such as Java and C99).
+Another helpful tool is the :func:`math.fsum` function which helps mitigate
+loss-of-precision during summation. It tracks "lost digits" as values are
+added onto a running total. That can make a difference in overall accuracy
+so that the errors do not accumulate to the point where they affect the
+final total:
+
+ >>> sum([0.1] * 10) == 1.0
+ False
+ >>> math.fsum([0.1] * 10) == 1.0
+ True
.. _tut-fp-error: