Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | 1x | export function kahanSum(values: Iterable<number>) { /* Return the kahan summation of the input number array */ let accumulator = 0; let compensation = 0; for (const value of values) { const y = value - compensation; const t = accumulator + y; compensation = (t - accumulator) - y; accumulator = t; } return accumulator; } |