This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]