gcc 4.4.2 : float multiplication 4097*4097 seems to be off by 1

Ian Lance Taylor iant@google.com
Fri Nov 12 06:42:00 GMT 2010


0throot <0throot@0throot.com> writes:

> In one of my programs, I found a wierd problem with float multiplication. Any
> insights you can provide will be very helpful.
>
> The program is as follows,
>
> #include <stdio.h>
> int main(void) { float a=4097, b=4097, c=0; c=a*b; printf("%12.2f != %d\n",
> c, 4097*4097); return 0; }
>
> The output i get is,
>
> 16785408.00 != 16785409
>
> I never thought using float over int could have such adverse effects. 
>
> Is this the correct behavior ? or am i doing something wrong here ?


http://docs.sun.com/source/806-3568/ncg_goldberg.html

Ian



More information about the Gcc-help mailing list