News for hackers. Stuff that matters.
Re:Comparing Floating-Point Numbers Is Tricky by bicsi on Saturday October 22, 2022 @12:58PM (#33299994)
The story is much worse than what is presented in the article, especially when talking about floating point errors that add (or rather multiply) up.

More often than not, the error is relative wrt the greatest magnitudes in the intermediary calculations. In essence, if you subtract two floating point numbers, you’re kinda screwed, because you cannot ever handle with good precision cases like A - B, where A and B are big enough numbers. Not to mention more complicated operations like trig functions.

In my opinion, one should avoid floating point as much as possible. And not only when testing for equality (all comparisons suffer from this).

Or, of course, ignore FPEs and proceed at your own risk.

[dead]
Re:Comparing Floating-Point Numbers Is Tricky by tomxor on Thursday October 27, 2022 @07:01PM (#33365179)
Indeed. The only way to accommodate numbers where the difference in order of magnitude exceeds the type's significand length is to not combine them, keep them separate and operate on them separately, combining them only for a sample.

One good common example is numerical integration. In any sufficient fine grained posteriori simulation, even with modest limits on position - delta velocity can be too small to preserve when adding to position, i.e when delta velocity is more than 2^52 smaller than position. Keeping a separate accumulator is the only way to handle this without arbitrarily increasing precision with software FP.