I am a little familiar with the problems associated with performing floating point equality comparisons in code.
Currently, the code base that I am compiling on (GCC, Clang) includes the following parameter: -Wfloat-equal
And in the code base there is the following comparison example:
template <typename FloatType>
void foo(FloatType v) {
if (v == FloatType(1)) {
...
}
else if (v == FloatType(0)) {
....
}
}
The foo function is called as follows:
double d = 123.98;
float f = 123.98f;
foo(d);
foo(f);
Given the special case of 1 and 0, each of which has exact representations in floating points (double, float) and where the code is clearly after exact equality, and not what is close by some slight difference -
, Wfloat- , , ?