Interesting floating-point summation tip [ ]:

"Raymond Hettinger @raymondh

floating point ninja tip: Use parentheses to regroup sums to minimize accumulated round-off error.

Instead of:
a + b + c + d + e + f + g + h

((a + b) + (c + d)) + ((e + f) + (g + h))

Note, the total work is unchanged."

For more on this see [ ]

· · Web · 1 · 2 · 4

For more accuracy, consider Kahan Summation...

"In particular, simply summing n numbers in sequence has a worst-case error that grows proportional to n, and a root mean square error that grows as √n for random inputs. With compensated summation, the worst-case error bound is effectively independent of n, so a large number of values can be summed with an error that only depends on the floating-point precision."



Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!