Closed chmike closed 3 years ago
It seams that this web document presents a far more efficient solution: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
Yes, the code is absolutely not optimized for performance - if anything it's optimized to show off how many special cases you need to allow for. And if you do need a performance-optimized version than most of all (as I wrote) you need to tailor it to your specific usecase, which may allow you to drop some special cases.
And the far more efficient solution you link to is actually mentioned in the next section ("Comparing floating-point values as integers") with a link to exactly the same article.
The code to test if floats are nearly equal is not very efficient. It is a problem when the test is to be performed in speed critical application like graphic.
Could there be a more efficient solution ?