From: mattias () thep ! lu ! se
To: tru64-unix-managers
Subject: SUMMARY: Another "cc -O2" compiler bug?
Date: Tue, 10 Jan 1995 08:23:12 +0000 [thread overview]
Message-ID: <96075316706398.tru64-unix-managers.marc@archive.invalid> (raw)
Thanks to all those who replied.
The problem was compiling with -O2 (and higher) optimization.
The code below is an example where -O2 gives the wrong answer.
------------------
#include <stdio.h>
#include <math.h>
void tmp( double );
void main()
{
double x;
x = 1.0;
tmp(x);
}
void tmp( double xx )
{
double fkn1, fkn2, arg, aux1, aux2;
aux2 = xx;
aux1 = 1.0;
/** original definition - gives the inverse of the correct thing **/
fkn1 = exp(-aux1 * aux2);
/** alternative definition - gives the correct result **/
arg = aux1 * aux2;
fkn2 = exp(-arg);
printf("%f %f %f %f\n", xx, fkn1, fkn2, fkn1 * fkn2);
}
------------------
I got 6 answers all confirming the bug.
One can, however use the -migrate compiler option
to get around the problem.
>> cc -migrate -O2 -o bug bug.c -lm
gives you the right answer.
Thanks again,
/Mattias
---------------------------------
Mattias Ohlsson
Department of Theoretical Physics
Lund University
Sweden
---------------------------------
reply other threads:[~1995-01-10 8:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox