7642 – [3.2 regression] optimization problem with signbit() (original) (raw)

Description anonymous 2002-08-19 23:06:00 UTC

The following program illustrates an optimization problem with signbit() of a long double NAN:

#include <math.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { long double n = NAN; if (signbit(n)) { fprintf(stdout, "n is negative\n"); } else { fprintf(stdout, "n is positive\n"); } exit(0); }

When compiled with

gcc -D_XOPEN_SOURCE=600 -o Test1 Test1.c

the resulting Test1 correctly prints "n is positive". When compiled with

gcc -D_XOPEN_SOURCE=600 -O -o Test1 Test1.c

or

gcc -D_XOPEN_SOURCE=600 -O2 -o Test1 Test1.c

the resulting Test1 incorrectly prints "n is negative". I am using gcc 3.2 on SuSE Linux/x86 7.1 (Linux kernel 2.4.0 and glibc 2.2).

Release: gcc 3.2

Environment: gcc 3.2 on SuSE Linux/x86 7.1 (kernel 2.4.0 and glibc 2.2)