← Back to context

Comment by eru

3 years ago

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.

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.)

  • 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.

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