Bug 14367 - inconsistent floating point results in C++ operator *= method
Summary: inconsistent floating point results in C++ operator *= method
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-01 16:56 UTC by Diab Jerius
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i486-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Diab Jerius 2004-03-01 16:56:24 UTC
A floating point calculation returns different results when performed in a
class's *= method vs. in main().  I'm not sure if the *= method is special, but
that's where it shows up.  The inconsistency is triggered by particular values
used in the calculation. 

I've seen this behavior in 3.3.3, and 3.2.3.  It does not appear in 3.1.
I've seen the behavior in the Debain (unstable) version of 3.3.3, as well as in
a personally compiled version of 3.2.3.  The resultant compiled code exhibits
the inconsistency on an AthlonMP, an Athlon, and an Intel Xeon.


At the end of this message is a uuencoded preprocessed program which exhibits
the behavior.  The code prints out the input and resultant values for the
calculation as done in the *= method and in main.  The resultant values should
be the same, but differ.  On my machines, here's the output:

1> 1582081461419629824 = 1804289383 * 1681692777 - 846930886 * 1714636915
2> 1582081461419630080 = 1804289383 * 1681692777 - 846930886 * 1714636915
1 != 2

The second value is the correct one.


malaise% /usr/bin/g++ -v -save-temps -O2 std_complex_dbl.cc -o std_complex_dbl
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian)
 /usr/lib/gcc-lib/i486-linux/3.3.3/cc1plus -E -D__GNUG__=3 -quiet -v
-D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE
std_complex_dbl.cc -O2 std_complex_dbl.ii
ignoring nonexistent directory "/usr/i486-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/3.3
 /usr/include/c++/3.3/i486-linux
 /usr/include/c++/3.3/backward
 /usr/local/include
 /usr/lib/gcc-lib/i486-linux/3.3.3/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i486-linux/3.3.3/cc1plus -fpreprocessed std_complex_dbl.ii
-quiet -dumpbase std_complex_dbl.cc -auxbase std_complex_dbl -O2 -version -o
std_complex_dbl.s
GNU C++ version 3.3.3 (Debian) (i486-linux)
        compiled by GNU C version 3.3.3 (Debian).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
 as -V -Qy -o std_complex_dbl.o std_complex_dbl.s
GNU assembler version 2.14.90.0.7 (i386-linux) using BFD version 2.14.90.0.7
20031029 Debian GNU/Linux
 /usr/lib/gcc-lib/i486-linux/3.3.3/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o std_complex_dbl
/usr/lib/gcc-lib/i486-linux/3.3.3/../../../crt1.o
/usr/lib/gcc-lib/i486-linux/3.3.3/../../../crti.o
/usr/lib/gcc-lib/i486-linux/3.3.3/crtbegin.o -L/usr/lib/gcc-lib/i486-linux/3.3.3
-L/usr/lib/gcc-lib/i486-linux/3.3.3/../../.. std_complex_dbl.o -lstdc++ -lm
-lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/i486-linux/3.3.3/crtend.o
/usr/lib/gcc-lib/i486-linux/3.3.3/../../../crtn.o

begin 644 std_complex_dbl.ii.bz2
M0EIH.3%!62936:0X(/``"<I_@']0__O_____O^_?+K____I@&K]X`%]YZ+PZ
M;QJKVVRWNWO4Q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#41`01@P;0'N]&@:W5V,,,VC;W>8FP.9*`VRNVVP
M6'@6X(9FGE0R3!M!#$>B:JDP6$`VHH3G,PUS6A7('9#II"24N=4<H%EH//P\
MBT$415!(QB8$@QDDG,;J2&$"E"E).@>?(4-%Q$,G(YY!0(Z;!(Y2O.8H&DA7
MX&>ZU!@JS:VXI5`;5(<_73=@I>`0H!#KH$0!-9L,#8"-4>>`;,*`8OA\Z=JI
MX$]EJ*'?CE"I!%A\UUE@P54061)X9.SL2(>U.J@,<:$!OH`-\2$J=:$5^>U`
MQ;-85BJ[!,115FX&2$B8]Q(.JP[C1(30EG5'('%H$&@+<IE=:YE1V[41=P':
MKK0(N94=^!.<@<R/2/!X@873VMHF^!Y45?691%5DC)WKMO4453KA)AS$`.=@
M*=&'?.N2LLZH;CQ`9+#Q@;EOM@Z8,D^%4H0AQ5U!#S0L3$4V)%134/A5#)53
A4MW@<*HY.V$`D!D$D!_J$B<^#8213_Q=R13A0D*0X(/`
`
end
Comment 1 Andrew Pinski 2004-03-01 17:28:47 UTC
In fact neither is correct (well really both are as for rounding errors which can happen and does).
The correct answer is 1582081461419629901.
But really this is a non-bug as you are dealing with FP and x86 where different precision can happen.
This is a dup of bug 323.

*** This bug has been marked as a duplicate of 323 ***