Follow

Interesting floating-point summation tip [ twitter.com/raymondh/status/13 ]:

"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

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

Note, the total work is unchanged."

For more on this see [ en.wikipedia.org/wiki/Pairwise ]

· · 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."

en.wikipedia.org/wiki/Kahan_su

#computerscience
#compsci
#WilliamKahan

@sohkamyung

Sign in to participate in the conversation
Mastodon

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