News for hackers. Stuff that matters.
Re:There Are Only Four Billion Floats–So Test Them All (2014) by eru on Thursday February 09, 2023 @05:50PM (#34732849)
That's not a general solution.

(And if you know what you are doing, you can also compare floats exactly in some circumstances.)

But the article already mentions that.

Re:There Are Only Four Billion Floats–So Test Them All (2014) by kccqzy on Thursday February 09, 2023 @07:22PM (#34733794)
Absolutely. I was once refactoring some badly written floating point code. To make sure I did not screw up, I want the result of the old and new code to be identical, since I know the refactoring should not change the float operations. (I also knew the code won't produce NaNs so == suffices.)
Re:There Are Only Four Billion Floats–So Test Them All (2014) by k0k0r0 on Friday February 10, 2023 @03:18AM (#34737010)
Oh, yes... This. Had a project like this not long ago. NaNs almost killed me. The code used complex numbers, and you know who their userbase is. Anyway, exact floating point comparisons made all of this possible.

In the process my coworker and found something we believed to be a bug with complex nans in some recent GCC versions, but where not smart enough to understand whether it is actually a bug or undefined behaviour in the standart.

Anyway, we where so exhausted from the refactor, we didn't follow it up again.

Re:There Are Only Four Billion Floats–So Test Them All (2014) by FpUser on Friday February 10, 2023 @01:17AM (#34736277)
>"And if you know what you are doing"

I knew what I was doing and that is why using Epsilon was the most reliable thing in my data processing algos.

Re:There Are Only Four Billion Floats–So Test Them All (2014) by eru on Friday February 10, 2023 @04:33AM (#34737497)
Hence the 'in some circumstances'.
Re:There Are Only Four Billion Floats–So Test Them All (2014) by FpUser on Friday February 10, 2023 @09:17AM (#34739844)
I can not recall when did I ever need to do "if X=Y" without actually needing to account for tolerances.
Re:There Are Only Four Billion Floats–So Test Them All (2014) by eru on Monday February 13, 2023 @08:41AM (#34773229)
Your experience seems a bit limited then?

Obviously, you need to account for tolerances, but that accounting does not need to be via an epsilon in your count, it can also take the form of careful numerical analysis. For example, in some numerical algorithms, it is right and proper to run them until an equality test (without epsilon) succeeds. And using any positive epsilon would give a worse result.