Open this example in the interactive library
Source code
import math
values = [1e16, 1, -1e16]
print(math.fsum(values))Sample output
1.0

Sum floats with reduced cancellation error in Python.
Open this example in the interactive library
import math
values = [1e16, 1, -1e16]
print(math.fsum(values))1.0