sum accuracy
Peter Otten
__peter__ at web.de
Wed Apr 13 13:03:06 EDT 2016
Robin Becker wrote:
> Does anyone know if sum does anything special to try and improve accuracy?
> My simple tests seem to show it is exactly equivalent to a for loop
> summation.
If you are worried about accuracy and your values are floating point numbers
use math.fsum():
"""
fsum(...)
fsum(iterable)
Return an accurate floating point sum of values in the iterable.
Assumes IEEE-754 floating point arithmetic.
"""
More information about the Python-list
mailing list