GH-100425: Improve accuracy of builtin sum() for float inputs (GH-100426)

This commit is contained in:
Raymond Hettinger 2022-12-23 14:35:58 -08:00 committed by GitHub
parent 1ecfd1ebf1
commit 5d84966cce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 8 deletions

View file

@ -192,7 +192,7 @@ 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
>>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0
False
>>> math.fsum([0.1] * 10) == 1.0
True