The following program (adapted from here ) gives inconsistent results when compiling with GCC (4.8.2) and Clang (3.5.1). In particular, the GCC result does not change even when FLT_EVAL_METHOD does.
#include <stdio.h> #include <float.h> int r1; double ten = 10.0; int main(int c, char **v) { printf("FLT_EVAL_METHOD = %d\n", FLT_EVAL_METHOD); r1 = 0.1 == (1.0 / ten); printf("0.1 = %a, 1.0/ten = %a\n", 0.1, 1.0 / ten); printf("r1=%d\n", r1); }
Tests:
$ gcc -std=c99 tc && ./a.out FLT_EVAL_METHOD = 0 0.1 = 0x1.999999999999ap-4, 1.0/ten = 0x1.999999999999ap-4 r1=1 $ gcc -std=c99 -mpfmath=387 tc && ./a.out FLT_EVAL_METHOD = 2 0.1 = 0x0.0000000000001p-1022, 1.0/ten = 0x0p+0 r1=1 $ clang -std=c99 tc && ./a.out FLT_EVAL_METHOD = 0 0.1 = 0x1.999999999999ap-4, 1.0/ten = 0x1.999999999999ap-4 r1=1 $ clang -std=c99 -mfpmath=387 -mno-sse tc && ./a.out FLT_EVAL_METHOD = 2 0.1 = 0x0.07fff00000001p-1022, 1.0/ten = 0x0p+0 r1=0
Note that according to this blog post, GCC 4.4.3 is used to output 0 instead of 1 in the second test.
A possibly related question indicates that the bug was fixed in GCC 4.6, which may explain why the GCC result is different.
I would like to confirm whether any of these results will be incorrect or if some subtle stages of the evaluation (for example, new preprocessor optimization) justify the difference between these compilers.
c gcc floating-point clang
anol
source share