Hi
the followiing code is giving 1 as answer but answer should be 0 ...becoz 0.7 is not grater than 0.7
please tell me the reasonCode:int main()
{
float a=0.7;
printf("%d",(0.7>a));
}
Printable View
Hi
the followiing code is giving 1 as answer but answer should be 0 ...becoz 0.7 is not grater than 0.7
please tell me the reasonCode:int main()
{
float a=0.7;
printf("%d",(0.7>a));
}
It's due to the way the numbers are stored. 0.7 cannot be accurately stored, only approximated, with a float. However, when you compare it to the other 0.7, you're likely comparing a float (a) to a double (0.7). The double has more accuracy, and can store a value that is more accurate (and apperanly larger) than a.
If you change "float" to "double", your comparison will probably fail.
thanks for your information
Interesting...
http://cboard.cprogramming.com/showt...ight=float+0.7
http://cboard.cprogramming.com/showt...ight=float+0.7
You're all using the same constant.
How about "most assuredly" instead of "probably?" Finite precision or not, the literal "0.7" will translate to the same double precision value in either context. Doubles are not infinitely precise; that doesn't mean they have some kind of quantum uncertainty ;)