In c++17, let's consider the following.
float num1 = 3.1005;
float num2 = 1.0005, num3 = 2.1000;
float res = num2 + num3;
Then, I would imagine res = 3.1005
and consequently res == num1 -> TRUE
. But that is not the result I get.
More confusingly,
cout << res; --> output: 3.1005
cout << (res == num1); --> output: false
Furthermore,
cout << fixed;
cout.precision(3);
cout << res; --> output: 3.100
cout << num1; --> output: 3.101
Can someone, please, explain to me why this is happening.