c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
Jos van den Oever
jos@vandenoever.info
Wed May 21 12:39:00 GMT 2003
Another addition to the report.
Comparing doubles in c does work properly:
#include <stdio.h>
#include <float.h>
int
main() {
double one = 1.0;
double belowone = 1.0-DBL_EPSILON;
if (one == belowone) {
printf("one == belowone\n");
} else {
printf("one != belowone\n");
}
if (1.0 == 1.0 - DBL_EPSILON) {
printf("1.0 == 1.0 - DBL_EPSILON\n");
} else {
printf("1.0 != 1.0 - DBL_EPSILON\n");
}
return 0;
}
gives output:
one != belowone
1.0 != 1.0 - DBL_EPSILON
which is what you'd expect.
More information about the Gcc-bugs
mailing list