On this page
math.fsum
Prev: math.frexp | Up: math | Next: math.gamma
Rel: math.acos, math.acosh, math.asin, math.asinh
Ref: docs.python.org — math.fsum
Tags: #public #python3 #stdlib #math
Import
import math
from math import fsum
Signature & Overview
math.fsum(seq, /)
Return an accurate floating-point sum of values in the iterable seq.
Usage
import math
vals = [0.1] * 10
assert math.fsum(vals) == 1.0
Gotchas
- Full-precision float summation: Eliminates accumulated rounding error compared to built-in
sum()(at a small speed cost).
REPL Inspect
from math import fsum
help(fsum)
Linked from
Related notes
- tuts/python3/stdlib_module/math/frexp Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/gamma Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/math/acos Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/acosh Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asin Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asinh Linked here; shared tags: #math, #stdlib
- tuts/c/stdlib/math shared tags: #math, #stdlib
- tuts/c/stdlib/math/fabs shared tags: #math, #stdlib
- tuts/c/stdlib/math/floor shared tags: #math, #stdlib