How to get an accurate floating point sum of values from a tuple in Python

3 Answers

0 votes
import math

print(math.fsum((-34.3, -12.1, 99.9, -51.6, 13.9)))


'''
run:

15.800000000000008

'''

 



answered Oct 14, 2017 by avibootz
0 votes
import math

Tuple = (-34.3, -12.1, 99.9, -57.6, 13.9)

print(math.fsum(Tuple))


'''
run:

9.800000000000008

'''

 



answered Oct 14, 2017 by avibootz
0 votes
import math

Tuple = (-34, -12, 99, -57, 13)

print(math.fsum(Tuple))


'''
run:

9.0

'''

 



answered Oct 14, 2017 by avibootz
...