This is a cut down version of some fp classification code. The odd thing is that it gets the correct answer with -O1 or with -mcpu=pentium4 -mfpmath=sse, but is incorrect at -O0. Using 3.2.3 -O0 and -O1 both work. the following code should print out 4094: ---- extern int printf(const char *,...); typedef union { double d; unsigned long long ull; } doublebits; inline int func(double x) { doublebits bits; bits.d = x; printf("%llu\n", bits.ull >> 51); return 0; } int main(int argc, const char **argv) { doublebits snan; snan.ull = 0x7ff0000000000001ULL; func(snan.d); return 0; } ---- > /dept/rnd/vendor/gcc-3.3.1-20030720/bin/gcc -O0 longlong.c -o longlong > ./longlong 4095 > /dept/rnd/vendor/gcc-3.3.1-20030720/bin/gcc -O1 longlong.c -o longlong > ./longlong 4094 > /dept/rnd/vendor/gcc-3.3.1-20030720/bin/gcc -O0 -march=pentium4 -mfpmath=sse longlong.c -o longlong > ./longlong 4094 > /dept/rnd/vendor/gcc-3.2.3/bin/gcc -O0 longlong.c -o longlong > ./longlong 4094
This is caused by loading and then storing by the floating point registers, so this is not a bug; It is the excessive precession on x86 with gcc so this is a dup of bug 323. *** This bug has been marked as a duplicate of 323 ***