[Python-checkins] r71994 - python/branches/py3k/Doc/tutorial/floatingpoint.rst

raymond.hettinger python-checkins at python.org
Mon Apr 27 00:01:46 CEST 2009


Author: raymond.hettinger
Date: Mon Apr 27 00:01:46 2009
New Revision: 71994

Log:
Add link to math.fsum().

Modified:
   python/branches/py3k/Doc/tutorial/floatingpoint.rst

Modified: python/branches/py3k/Doc/tutorial/floatingpoint.rst
==============================================================================
--- python/branches/py3k/Doc/tutorial/floatingpoint.rst	(original)
+++ python/branches/py3k/Doc/tutorial/floatingpoint.rst	Mon Apr 27 00:01:46 2009
@@ -189,6 +189,16 @@
 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:
 


More information about the Python-checkins mailing list