Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Array Ordering and Naive Summation (julialang.org)
2 points by aw1621107 on Nov 13, 2021 | hide | past | favorite | 3 comments


Thought this was a fascinating example of the perils of naive floating-point summation. I knew that one had to be careful with floating-point math, but I had no idea that this kind of thing was possible:

> The sumsto function always returns the same 2046 floating-point numbers but returns them in a different order based on x: for any 64-bit float value of x from 0 up to (but not including) 2^970, the naive left-to-right sum of the vector returned by sumsto(x) is precisely x


It's very rare that you sum numbers separated by ~100 orders of (decimal) magnitude. In practice the error will usually be very small. Just big enough to make x == y and x != y useless for floats, but not big enough to cause problems anywhere else.


Yeah, that's a fair point. I just thought that this was an interesting example of what is possible more than what one would need to worry about in practice.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: