Can someone explain why the output of the following piece of code is as below?
float x = std::numeric_limits<float>::max();
float y = x - 1.0f;
if(x==y)
std::cout << "x is equal y!\n";
else
std::cout << "x is not equal y!\n";
std::cout << std::fixed << "x: " << x << "\n";
std::cout << std::fixed << "y: " << y << "\n";
On my machine, where the size of a float
is 4 bytes, the output looks like this:
x is equal y!
x: 340282346638528859811704183484516925440.000000
y: 340282346638528859811704183484516925440.000000
Thanks in advance:-)