All files / src/util float.ts

8.33% Statements 1/12
100% Branches 0/0
0% Functions 0/1
11.11% Lines 1/9

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 131x                        
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;
}