delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/11/17/04:24:14

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
x-cr-hashedpuzzle: BG6f BuhZ B/Gt CFbd CIt7 DUNO Dqmu EFzB FugD Fu4w Gmdn G+Hw HuJ9 ILmF JJ9l Kuop;1;YwB5AGcAdwBpAG4AQABjAHkAZwB3AGkAbgAuAGMAbwBtAA==;Sosha1_v1;7;{FE2AB9F0-0D4C-467A-9FB2-75ED858401AC};ZQByAGkAYwBfAGIAYQBjAGsAdQBzAEAAYQBnAGkAbABlAG4AdAAuAGMAbwBtAA==;Tue, 17 Nov 2009 09:22:04 GMT;ZwBjAGMAIAAtAGYAZgBhAHMAdAAtAG0AYQB0AGgAIABkAGUAZgBlAGMAdAAgAHcAaQB0AGgAIAB0AGEAbgAoAHgAKQA=
x-cr-puzzleid: {FE2AB9F0-0D4C-467A-9FB2-75ED858401AC}
Subject: gcc -ffast-math defect with tan(x)
Date: Tue, 17 Nov 2009 02:22:04 -0700
Message-ID: <AE5F3949C74C6547AEAEAB87D1AC7F1B057788A6@cos-us-mb01.cos.agilent.com>
From: <eric_backus AT agilent DOT com>
To: <cygwin AT cygwin DOT com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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:


#include <stdio.h>
#include <math.h>

int main(void)
{
    double d1 =3D 0.0;
    double d2 =3D 0.0;
    d1 =3D tan(d1);
    d2 =3D tan(d2);
    (void) printf("d1 =3D %lg, expecting 0 (or -0)\n", d1);
    (void) printf("d2 =3D %lg, expecting 0 (or -0)\n", d2);
    return 0;
}


Compile this with "gcc -ffast-math testprog.c -o testprog", then run "./tes=
tprog".  Correct output would be:

d1 =3D 0, expecting 0 (or -0)
d2 =3D 0, expecting 0 (or -0)

Some time ago, on cygwin 1.5 and presumably with an older version of gcc, t=
his code (well, actually, a more complicated version of this in a library w=
e use) worked correctly.  It worked correctly both with and without "-mno-c=
ygwin", and both with and without -ffast-math.

Today, on cygwin 1.7, I get this output:

d1 =3D -0, expecting 0 (or -0)
d2 =3D 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 expe=
cted 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 b=
oth d1 and d2.  So the problem seems to be limited to -ffast-math, and to t=
he 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!

--=20
Eric



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019