6 ms·
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
by throwaway260124 2y 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.
- Chabsff 2y agoNot necessarily. If the array is large and the values are similar, using accumulators would yield a more accurate result than a single one.
- celrod 2y agoMultiple accumulators increases accuracy. See pairwise summation, for example. SIMD sums are going to typically be much more accurate than a naive sum.
- Chabsff 2y agoNot 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.
- kardos 2y ago> There just isn't a one-size-fit-all solution to be had here. But there is: https://news.ycombinator.com/item?id=40867842 https://news.ycombinator.com/item?id=40867842
- bee_rider 2y agoThat’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.