New blog post! I really hope I'll get a decent amount of people mad with this one 😈😈😈

It's OK to compare floating-points for equality:

https://lisyarus.github.io/blog/posts/its-ok-to-compare-floating-points-for-equality.html

#programming #computing #floatingpoint #geometry

It's OK to compare floating-points for equality

lisyarus blog

@lisyarus Thanks a lot! This is one of my larger pet peeves. In the last 10 years I probably needed exact comparisons 95%+ of the time (if you exclude test code). And I mostly regretted any epsilon comparison in time. This is all with the exception of tests, where "approximate equal to the expected result" is fine.

But basically "load-bearing" comparisons with eps didn't bear any load in the end...

@artificialmind Yep, that's pretty much what my own experience was as well!

@lisyarus I had one client who had operator== on their Vector3 class overloaded with a non-zero epsilon.

Can you imagine how a std::unordered_map behaves if the equality operator might pick up the wrong element? That's fun to debug.