Interesting floating-point summation tip [ https://twitter.com/raymondh/status/1301800636866940928 ]:
"Raymond Hettinger @raymondh
#Python floating point ninja tip: Use parentheses to regroup sums to minimize accumulated round-off error.
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 [ https://en.wikipedia.org/wiki/Pairwise_summation ]
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."
The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!