If operator< works properly for floating-point types, why can't we use it for equality testing?
Properly testing two floating-point numbers for equality is something that a lot of people, including me, don't fully understand. Today, however, I thought about how some standard containers define equality in terms of operator< . I always see people with problems surrounding equality, but never with the other relational comparisons. There are even silent versions of them to use, which include everything except for equality and inequality. Assuming operator< works "properly", unlike operator== , why couldn't we do this: bool floateq(float a, float b) { //check NaN return !(a < b) && !(b < a);