floating-point-comparison
Why does Release/Debug have a different result for std::min?
In IEEE 754 comparing NAN to anything will always yield false, no matter what it is. slope > 0; // false slope < 0; // false slope == 0; // false And, more importantly for you slope < DBL_MAX; // false DBL_MAX < slope; // false So it seems that the compiler reorders the parameters/uses … Read more
In C++, is exactly one of guaranteed to be true on floats?
No. It’s enough for either a or b to be NaN for each of a < b, a == b and a > b to be false. If both a and b are non-NaN then exactly one of a < b, a == b or a > b has to be true. In complement, this … Read more
Floating point equality
However, I wonder, are there any cases, when using == is perfectly fine? Sure there are. One category of examples are usages that involve no computation, e.g. setters that should only execute on changes: void setRange(float min, float max) { if(min == m_fMin && max == m_fMax) return; m_fMin = min; m_fMax = max; // … Read more