Real numbers are stored in the form of a mantissa and exponent.
Float in glibc uses 6 decimal digits as the precision of the mantissa. Check out "/usr/lib/gcc-lib/i386-redhat-linux/3.0.2/include/float.h" --------------------------- /* Number of decimal digits of precision in a float */ #undef FLT_DIG #define FLT_DIG 6 --------------------------- This explains your second output. However, I am at a loss at the first output. While I cant explain that, the fact that the difference is near a power of 2 suggests that it has got something similar to do with the storage of the mantissa again. - Sandip On Wed, Jan 30, 2002 at 01:23:41AM -0500, Vertical rains spoke out thus: > hello everyone > > i have the following program > > /////////////////////////////////// > > #include <stdio.h > #include <iostream.h > void main () > { > float x = 1073741855; > > printf ("%f\n", x); > cout << x; > } > > ////////////////////////////////// > > and the out put on running is as follows > > 1073741824.000000 > 1.07374e+09 > > What i want to know is that why am i not > getting the o/p as 1073741855 .There is a > difference > of 31.What am i doing wrong? > ====for those who posted > suggestions==== > I would not like to change the data type > to something else as the float can > definitely hold this value > And i also did try declaring the value of > x as float x=1073741855.0; instead of float > x=1073741855; > Used the <iostream.h> and <stdio.h> > mutually exclusively so that they do not > clash with each other > > It does'nt help and the o/p is still the > same. > > So somebody please HELLLLLLLLLLPPPPPPPPP > > Thanks everybody. > Regards > Virindera > > > > -- > > _______________________________________________ > Win a ski trip! > http://www.nowcode.com/register.asp?affiliate=1net2phone3a > > > ================================================ > To subscribe, send email to [EMAIL PROTECTED] with subscribe in subject header > To unsubscribe, send email to [EMAIL PROTECTED] with unsubscribe in subject >header > Archives are available at http://www.mail-archive.com/ilugd%40wpaa.org > ================================================= -- Sandip Bhattacharya sandipb @ bigfoot.com http://www.sandipb.net ---------------------------- ================================================ To subscribe, send email to [EMAIL PROTECTED] with subscribe in subject header To unsubscribe, send email to [EMAIL PROTECTED] with unsubscribe in subject header Archives are available at http://www.mail-archive.com/ilugd%40wpaa.org =================================================