This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 4.4.2 : float multiplication 4097*4097 seems to be off by 1
- From: Ian Lance Taylor <iant at google dot com>
- To: 0throot <0throot at 0throot dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 11 Nov 2010 22:41:48 -0800
- Subject: Re: gcc 4.4.2 : float multiplication 4097*4097 seems to be off by 1
- References: <30196626.post@talk.nabble.com>
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