How to deal with overflows while using either Welford's or Youngs-Cramer algorithms for variance?

188 Views Asked by At

I'm trying to use either of the mentioned algorithms to calculate sample variance. However I ran into this problem -- Welford's algorithm uses for accumulations a sum of differences of elements and accumulated mean. If the mean is close to 0, this basically turns into sum of squares of elements -- which leads to overflows if the elements and the number of them are big. Is there a way around that?