Kahan summation algorithm (source code)

= Kahan summation algorithm
{wiki=Kahan_summation_algorithm}

The Kahan summation algorithm, also known as compensated summation, is a numerical technique used to improve the precision of the summation of a sequence of floating-point numbers. It mitigates the error that can occur when small numbers are added to large numbers, a common issue in floating-point arithmetic due to limited precision. \#\#\# How it Works The algorithm maintains an extra variable (often called \`c\`, for "compensation") that keeps track of small error terms.