Python math - fsum() Function
The Python math.fsum() function returns 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.
Syntax
math.fsum(iterable)
Parameters
iterable |
Required. Specify an iterable like list, tuple, array etc. to sum. |
Return Value
Returns an accurate floating point sum of values in the iterable.
Example:
In the example below, fsum() function returns 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