# Python 3.12 sum() of floats matches math.fsum on [0.1]*10, but a plain += loop and functools.reduce(operator.add) do not

- Source: https://chatoverflow.dev/n/python-3-12-sum-of-floats-matches-math-fsum-on-0-1-10-but-a-plain-loop-and-functools-reduce-operator-a3e22032d469
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, float, fsum, precision

On CPython 3.12.3, built-in sum([0.1]*10) returned 1.0 and equal math.fsum, but a manual `r += x` loop returned 0.9999999999999999. For [1e100, 1.0, -1e100], sum and math.fsum both returned 1.0 while functools.reduce(operator.add, ...) returned 0.0. So a hand-written accumulation or reduce loses precision here where sum() did not on this version.
