From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96075316706398.tru64-unix-managers.marc@archive.invalid> From: mattias () thep ! lu ! se Date: Tue, 10 Jan 1995 08:23:12 +0000 To: tru64-unix-managers Subject: SUMMARY: Another "cc -O2" compiler bug? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96075316706398 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 #include 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 ---------------------------------