This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Bug in egcs-2.91.66 - double comparisons
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Bug in egcs-2.91.66 - double comparisons
- From: Richard Bielak <richieb at calfp dot com>
- Date: Tue, 19 Oct 1999 16:02:52 -0400
Hi,
I'm using egcs-2.91.66 on a RH 6.0 system:
Linux chippewa 2.2.9 #20 SMP Thu May 20 00:01:37 PDT 1999 i686 unknown
and I compile this program:
----------------------------------------------------------
#include <stdio.h>
int main (int argc, char **argv) {
double t1, t2, t3, t4;
t1 = 0.040000000000000008;
t2 = 0.20000000000000001;
t3 = 0.20000000000000001;
/* The comparison fails here */
if (t1 <= t3 * t2) {
printf ("Seems OK \n");
}
else {
printf ("Seems wrong \n");
}
t4 = t3 * t2;
/* Comparison OK here */
if (t1 <= t4) {
printf ("Seems OK \n");
}
else {
printf ("Seems wrong \n");
}
printf ("t1=%E t2=%E t3=%E t3*t2=%E \n", t1, t2, t3, t2 * t3);
}
--------------------------------------------------------
Depending on the kind of optimization I use the answers come out differently.
Here is what I type:
[richieb on chippewa] numbers > gcc -o doubles doubles.c
[richieb on chippewa] numbers > ./doubles
Seems wrong
Seems OK
t1=4.000000E-02 t2=2.000000E-01 t3=2.000000E-01 t3*t2=4.000000E-02
[richieb on chippewa] numbers >
[richieb on chippewa] numbers > gcc -O -o doubles doubles.c
[richieb on chippewa] numbers > ./doubles
Seems OK
Seems wrong
t1=4.000000E-02 t2=2.000000E-01 t3=2.000000E-01 t3*t2=4.000000E-02
[richieb on chippewa] numbers >
[richieb on chippewa] numbers > gcc -O2 -o doubles doubles.c
[richieb on chippewa] numbers > ./doubles
Seems OK
Seems OK
t1=4.000000E-02 t2=2.000000E-01 t3=2.000000E-01 t3*t2=4.000000E-02
[richieb on chippewa] numbers >
[richieb on chippewa] numbers >
[richieb on chippewa] numbers > gcc -O3 -o doubles doubles.c
[richieb on chippewa] numbers > ./doubles
Seems OK
Seems OK
t1=4.000000E-02 t2=2.000000E-01 t3=2.000000E-01 t3*t2=4.000000E-02
[richieb on chippewa] numbers >
The correct answer is that both comparisons should come out the same.
This code works OK with earlier versions of GCC (2.8.1).
Thanks for any help...
...richie