+ 1
Can any one explain why we got this kind of output and also say me when " float is true " and "double is false" gets printed ?
#include<stdio.h> int main() { float i =0.1; double j =0.1; if(i == 0.1) puts("float is true\n"); else puts("float is false\n"); if(j == 0.1) puts("double is true\n"); else puts("double is false\n"); return 0; } ------------- Output: ------------- float is false double is true
1 Respuesta
0
Floats and doubles are imprecise in computers, double less so than float.
I suppose the issue comes from there.
A few threads that discuss the matter (I suppose you can find many more):
https://www.sololearn.com/discuss/1855448/?ref=app
https://www.sololearn.com/discuss/1093191/?ref=app
https://www.sololearn.com/discuss/1733175/?ref=app
https://www.sololearn.com/discuss/1606645/?ref=app
https://www.sololearn.com/discuss/1159244/?ref=app
https://www.sololearn.com/discuss/796595/?ref=app