def kahan_sum(x): total = 0.0 c = 0.0 for v in x: y = v - c t = total + y c = (t - total) - y total = t return total