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
---------------------------------
Received on Tue Jan 10 1995 - 03:22:22 NZDT