3 ms·
Worth noting that Kahan summation works under the assumption that, at every step of the summation, the current sum will be larger than the term added. It is no
by nestorD 7y ago
Worth noting that Kahan summation works under the assumption that, at every step of the summation, the current sum will be larger than the term added.
It is not too hard modify the algorithm in order to remove this assumption and it increase the accuracy of the algorithm sensibly (but sadly a test, as suggested on the wikipedia page, is not the best way to do that).
Here is a Rust crate (not mine) that offers various implementation of increasing accuracy and an exact sum (slow but it will return the floating point that is closest to the sum of your inputs) : https://crates.io/crates/accurate https://crates.io/crates/accurate