Kahan summation algorithm Created 2026-10-20 Updated 2026-11-05
The Kahan summation algorithm computes a sum in floating-point arithmetic while carrying a correction for low-order information lost by successive additions. With accumulator and correction initially zero, process each input in this order:
y = x - c
t = s + y
c = (t - s) - y
s = t
Every operation shown is rounded in the working floating-point representation. The new approximates the portion added too much or too little in the rounded , so the next input subtracts it. For binary64 inputs in that order, ordinary left-to-right summation loses both small increments, returning one; this algorithm recovers .
The correction substantially improves many long sums, but is not an exact summation method and does not remove ill-conditioning when large opposite-sign terms nearly cancel. Its operation order is essential: a compiler that rewrites as exact algebraic zero destroys the correction.[ref]