I am performing a simple sum operation on float numbers using math.fsum()
function in Python but the result is not matching with what am expecting.
Please find the example below:
math.fsum([-5.2,-20.8,5,21])
#output : -8.881784197001252e-16
Ideally the output should be zero. What is the best way of calculating the sum of a list with both positive and negative float and int values? I have tried using sum
and fsum
. But in both the cases the outputs are not correct
math.fsum([-5.2,-20.8,5,21])
#output : -8.881784197001252e-16