Hi. I am testing a floating point division algorithm. I had tested several thousand division cases. In most case, the result was the same with the calculated result with FPU.
However, I found an error case for double precision floating-point division. The case is as follows; n = 1.600228...; d = 1.312790...; q = n/d; error in q : the last bit of the output is incorrect in 32-bit GCC compiler. (FPU rc = round to nearst even, the default rounding mode) (The actual number were written in 64-bit hex-decimal number) The following tool & envirionments output wrong answer: - i386-redhat-linux gcc 3.4.6 (Intel P4, (AMD Opteron is also tested)) - windows XP/cygwin/ gcc 3.4.4 (Intel Core2 duo) The following tool & environments output right answer: - Solaris10 gcc3.2.3, (Sparc) - x86_64-redhat-linux gcc 3.4.6 (AMD Opteron) - Visual C++ 6.0 (Intel Core2 duo) Only gcc for 32-bit envirionment outputs incorrect result. I think there may be a problem in FPU rc(rounding control) in GCC for 32-bit environment. I don't think it's not the problem of CPU h/w design because other compilers output the correct result. Although it's very small error in a floating number calculation, gcc might be regarded as an unreliable compiler in my field, computer arithmetic. I hope this problem will be fixed as soon as possible. Regards, Inwook Kong ------------ source code ------------ typedef unsigned long long int UINT64; int main(void) { int i,j; double n,d,q; //for test cases *((UINT64*)&n)=0x3ff99a89160f4c0ell; *((UINT64*)&d)=0x3ff5012fcd164611ll; q=n/d; printf("q=%llx\n",*((UINT64*)&q)); } -------------- output -------------- [output : i386-redhat-linux gcc 3.4.6] q=3ff380d464d7da48 <-incorrect value [correct output- Solaris10 gcc3.2.3, x86_64-redhat-linux gcc 3.4.6] q=3ff380d464d7da47 <- right value in IEEE-754 standard -------------- environment -------------- [Environment] Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux Thread model: posix gcc version 3.4.6 20060404 (Red Hat 3.4.6-9) [GCC option] CFLAGS = -c -save-temps LFLAGS = -lm -- Summary: A incorrect result in a simple division, only in 32-bit gcc. Product: gcc Version: 3.4.6 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: purnnam1 at naver dot com GCC build triplet: gcc version 3.4.6 20060404 GCC host triplet: i386-redhat-linux GCC target triplet: Red Hat 3.4.6-9 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35488