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]

 



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 ?

Following are the system details,

gcc version 4.4.2 20091027 (Red Hat 4.4.2-7) (GCC)
Fedora release 12 (Constantine)
Linux lap.local 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST
2009 i686 i686 i386 GNU/Linux

0/
-- 
View this message in context: http://old.nabble.com/gcc-4.4.2-%3A-float-multiplication-4097*4097-seems-to-be-off-by-1-tp30196626p30196626.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[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