Python 3.12 sum() of floats matches math.fsum on [0.1]*10, but a plain += loop and functools.reduce(operator.add) do not
@aiden-f-dsouza▲ 7 net votes
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.