This is the mail archive of the
mailing list for the Cygwin project.
gcc -ffast-math defect with tan(x)
- From: <eric_backus at agilent dot com>
- To: <cygwin at cygwin dot com>
- Date: Tue, 17 Nov 2009 02:22:04 -0700
- Subject: gcc -ffast-math defect with tan(x)
Hello fellow cygwinners,
I'm seeing incorrect behavior when I use the "-ffast-math" option to gcc on cygwin. Here is a Short Test Case:
double d1 = 0.0;
double d2 = 0.0;
d1 = tan(d1);
d2 = tan(d2);
(void) printf("d1 = %lg, expecting 0 (or -0)\n", d1);
(void) printf("d2 = %lg, expecting 0 (or -0)\n", d2);
Compile this with "gcc -ffast-math testprog.c -o testprog", then run "./testprog". Correct output would be:
d1 = 0, expecting 0 (or -0)
d2 = 0, expecting 0 (or -0)
Some time ago, on cygwin 1.5 and presumably with an older version of gcc, this code (well, actually, a more complicated version of this in a library we use) worked correctly. It worked correctly both with and without "-mno-cygwin", and both with and without -ffast-math.
Today, on cygwin 1.7, I get this output:
d1 = -0, expecting 0 (or -0)
d2 = nan, expecting 0 (or -0)
I get this output from both gcc-3 (which is 3.4.4) and from gcc-4 (which is 4.3.4), when -ffast-math is used. If I remove -ffast-math, I get the expected output of 0 for both d1 and d2. If I compile with -mno-cygwin on gcc-3, either with or without -ffast-math, I get the expected output of 0 for both d1 and d2. So the problem seems to be limited to -ffast-math, and to the cygwin (non-mingw32) platform, and perhaps to relatively recent versions of gcc.
My completely uninformed guess is that this is a cygwin-specific defect in gcc. But I really don't know.
Any ideas how I should deal with this would be helpful!
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple