I have noticed something very odd when using std::floor. I'm am compiling C++ on ubuntu. I'm trying to floor a double to the nearest hundredth and I'm checking the cases where the input value is already rounded to the nearest hundredth and I'm getting inconsistent results.
My code:
double hundredthFloor(double value){
double hundredth = 0.01;
return hundredth * std::floor( value / hundredth);
}
In most cases it works,
value = 99.87 gives output 99.87
value = 99.879 gives output 99.87
value = 0.39 gives output 0.39
However:
value = 0.29 gives value 0.28
value = 0.47 gives value 0.46
I've tried many input values and so far only 0.29 and 0.47 seem to output a value one decimal below what I'd expected.
Has anyone seen anything similar?