Hacker News new | ask | show | jobs
by throwaway260124 711 days ago
Sorting the floats reduces the error. I think using multiple accumulators reduces the accuracy then. And sorted data is not uncommon.

I think there is always a correct answer and the compiler shouldn’t make changes at least by default that are wrong.

But ways for the programmer to express his intent more clearly are always welcome.

2 comments

Not necessarily. If the array is large and the values are similar, using accumulators would yield a more accurate result than a single one.
Multiple accumulators increases accuracy. See pairwise summation, for example.

SIMD sums are going to typically be much more accurate than a naive sum.

Not necessarily either. It's not particularly hard to create a vector where in-order addition is the most accurate way to sum its terms. All you need is a sequence where the next term is close to the sum of all prior ones.

There just isn't a one-size-fit-all solution to be had here.

> There just isn't a one-size-fit-all solution to be had here.

But there is: https://news.ycombinator.com/item?id=40867842

That’s a one size fits some solution. Not more than 2x as slower than native floats is pretty slow for cases where you don’t need the extra precision.

If might be the case that it is the best solution if you do need the extra precision. But that’s just one case, not all.