Hacker News new | ask | show | jobs
by xurukefi 2650 days ago
How much precision loss is to be expected here?
2 comments

Good point. The precision loss will be pretty bad if the numbers added above have greatly different magnitudes, which could occur if the next number (x) is very different to the current mean (mu), or if the list is very long. The first issue could be partially mitigated by sorting the list first. If the list is very long, the above algorithm will necessarily add numbers of quite different magnitudes, but employing something like Kahan summation - https://en.wikipedia.org/wiki/Kahan_summation_algorithm , could partially mitigate that issue as well.
It is proportional to the number of terms in the sum. Kahan summation has a tighter error bound.