The question is really simple: consider two floats which are possibly not bitwise equal but difference is relatively small in all possible senses. Let's also assume that difference between their floors is smaller than some relatively small epsilon (0.01 should be definitely enough). Will their floors be bitwise equal (i.e. equal in terms of operator==)?
For example, will the code below return true
all the time:
bool areRoundedFloatsEqual(float lhs, float rhs) {
if (lhs > 0 && rhs > 0 && fabs(lhs - rhs) < 0.01) {
lhs = std::floor(lhs);
rhs = std::floor(rhs);
if (fabs(lhs - rhs) < 0.5)
return lhs == rhs;
}
return true;
}
In fact I'm interested in two questions:
- What will happen in the real life?
- What does standard say about it?
UPD
There was incorrect example I replaced with description. (Thanks @MarcGlisse and
@KevinBallard for pointing at the error.)
UPD 2 Here is the topic which covers this problem pretty good: Representable result of floor() and ceil()