C/float storage
Expert: Narendra - 6/14/2006
Questionhello Narendra
i want to ask about how float stores in memory?
because after seeing this program i am in great
confusion
float x=0.7;
if(x<0.7)
printf(" c");
else
printf("c++");
o/p is c .
but
float x=0.8;
if(x<0.8)
printf(" c");
else
printf("c++");
ans is c++
why is it so?
pls explain this ?
monika
AnswerThe reason for this is, the way float is represented in memory.
Usually IEEE standard is used for representation.
In that there are 3 parts: Mantissa, Exponent and sign.
So, when you say 0.7, it could have been represented as 0.000006999999 * (10 ^ 5).
So, no float number is represented as you see it on your computer.
Here are some url's, which explain about this in detail:
1.
http://scholar.hw.ac.uk/site/computing/topic21.asp?outline=
2.
http://wiki.tcl.tk/13206
3.
http://community.borland.com/article/0,1410,15855,00.html
4.
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
5.
http://www.markworld.com/showfloat.html
6.
http://en.wikipedia.org/wiki/IEEE_floating-point_standard
In the 5th url, you can actually enter a number and see how it gets split to different parts.
And the last one is a wiki page on the subject.
Hope this helps and clarifies.