Hacker News new | ask | show | jobs
by snovv_crash 2649 days ago
I ran into a similar issue doing high accuracy dot-products. The solution was Kahan summation [1], which first adds the incremental value, then checks the result to see how much floating point error was introduced, then rolls that error into the next addition.

I suspect something similar could be done here, even if it would be a few times slower, to get an ulp-accurate mean regardless of the order/size of the individual elements.

1: https://en.wikipedia.org/wiki/Kahan_summation_algorithm