How can I add floats together in different orders, and always get the same total?

Posted by splicer on Stack Overflow See other posts from Stack Overflow or by splicer
Published on 2010-04-24T11:52:49Z Indexed on 2010/04/24 12:03 UTC
Read the original article Hit count: 187

Let's say I have three 32-bit floating point values, a, b, and c, such that (a + b) + c != a + (b + c). Is there summation algorithm, perhaps similar to Kahan summation, that guarantees that these values can be summed in any order and always arrive at the exact same (fairly accurate) total? I'm looking for the general case (i.e. not a solution that only deals with 3 numbers).

Is arbitrary precision arithmetic the only way to go? I'm dealing with very large data sets, so I'd like to avoid the overhead of using arbitrary precision arithmetic if possible.

Thanks!

© Stack Overflow or respective owner

Related posts about numerical

Related posts about order