Python - math.fsum() Function
The Python math.fsum() function is used to return an accurate floating point sum of values in the iterable.
The algorithm's accuracy depends on IEEE-754 arithmetic guarantees and the typical case where the rounding mode is half-even. On some non-Windows builds, the underlying C library uses extended precision addition and may occasionally double-round an intermediate sum causing it to be off in its least significant bit.
Returns an accurate floating point sum of values in the iterable.
In the below example, fsum() function is used to return the sum of values in a given iterable.
import math MyList = [1.1, 2.2, 3.3] print("Sum of values: ", math.fsum(MyList))
The output of the above code will be:
Sum of values: 6.6
❮ Python Math Module