-
Junior Member
Program output
What do you think would be the output of the following program and why? (If you are about to say "f is 1.0", I would say check it out again)
#include
int main()
{
float f=0.0f;
int i;
for(i=0;i<10;i++)
f = f + 0.1f;
if(f == 1.0f)
printf("f is 1.0 n");
else
printf("f is NOT 1.0n");
return 0;
}
-
Junior Member
Re: Program output
Ouput is :
f is NOT 1.0n
This is because floating point numbers doesn't have accuracy in certain cases (unlike 'double'). The interpretation inside the machine will be different than what we see.Thus, even though we see the value as 1.0f, due to different storage interpretation, it will fail to compare with actual 1.0f.
The full article and details can be found in wikipedia related to floating point arithmatics.
-
Junior Member
Re: Program output
yet the result is coming out to be 1.0f but coz of the interpretiion of floating point numbers value gets diferent frm the value tat it ought to be....................
tat's y here result won't be 1.0f but somewat different frm tat.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules