Gosh darn it thanks Peter.
Here is where it gets weird.
23 is int(0.24 * 100), but if you do not typecast (0.24 * 100) to int, you get the value of 24 itself but also with no floating point.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <iostream>
int main() {
long double foo;
foo = 0.24;
std::cout<<foo*10*10; // <- comment this out
//std::cout<<int(foo*10*10); <- try this
std::cin.get();
return 0;
}
|
How does floating point decide when to round off?
Try
std::cout<<std::setprecision(4)<<foo*10*10
You will notice that there is no decimal point at all.
Now try multiplying by 10, you do not see the supposed 9999 in fact it would never show you the real value but behave like what inputted value itself while displaying and multiplying by 10 at least.
But yet when we do temp_floating - ceil(temp_floating) the compiler thinks there is a floating point.
Anybody has anything to add to above anomaly? Why isn't there a better more accurate implementation of floating point in STL?
So it's just impossible to represent 0.24 in binary?