This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]