0
What is the logic behind this? Tell me
Give a solution to this question. I thing that the correct answer is the "right" but the actual answer is not the same. Anybody explain me how it is.... #include <stdio.h> int main() { float f1=0.1; if(f1==0.1) printf("Equal"); else printf("not equal"); }
2 Answers
+ 1
0.1 is double. 0.1f is float.
Comparing float to double might get unexpected result, like in your code f1==0.1 returns false. Compare float to float. f1==0.1f returns true.
+ 1
f1 is float
0.1 is double
float 0.1 representation: 3d cc cc cd (32 bits ieee754)
double 0.1 representation: 3f b9 99 99 99 99 99 9a (64 bits ieee754)
They're not equal....!!