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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



0throot <0throot@xxxxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux