float a = 0.7;
if(a<0.7)
printf("true");
else
printf("false");
OUTPUT : true
Now , if I change the value of a to say 1.7 ,then
float a = 1.7;
if(a<1.7)
printf("true");
else
printf("false");
OUTPUT : false
Since 0.7 is treated as a double (HIGH PRECISION) and a is a float (LESS PRECISION) , therefore a < 0.7 , and in second case it should be the same again , so it should also print true. Why the difference in output here ?
PS : I have already seen this link.
If
floatanddoubleare IEEE-754 32 bit and 64 bit floating point formats respectively, then the closestfloatto exactly 1.7 is ~1.7000000477, and the closestdoubleis ~1.6999999999999999556. In this case the closestfloatjust happens to be numerically greater than the closestdouble.