Anatoly Vorobey wrote:

On Mon, Aug 08, 2005 at 06:30:58PM +0300, Ariel Biener wrote:
gcc -O2 -fno-math-errno -o /tmp/bnch-O2-no-math-errno /tmp/drek.c -lm
Try doing something with q after the loop to force it to compute sqrt,
that'll reflect reality better. printf or whatever. If you don't want
to call functions, use
Actually, something extremely weird it going on here. The result change, considerably, when I compile with or without "no-math-errno":

[EMAIL PROTECTED]:/tmp$ cat test.c
#include <stdio.h>
#include <math.h>

int
main(int argc, char **argv)
{
        long long i;
        double q;

        for (i=0; i<10000000; i++) {
                q += sqrt(i);
        }
        printf("%f\n", q);
}

[EMAIL PROTECTED]:/tmp$ gcc -O0 -o test -lm test.c && time ./test
21081849486.439266

real    0m0.986s
user    0m0.984s
sys     0m0.002s
[EMAIL PROTECTED]:/tmp$ gcc -O1 -o test -lm test.c && time ./test
21082188334.439266

real    0m0.769s
user    0m0.766s
sys     0m0.002s
[EMAIL PROTECTED]:/tmp$ gcc -O2 -o test -lm test.c && time ./test
21082188334.439266

real    0m0.765s
user    0m0.765s
sys     0m0.000s
[EMAIL PROTECTED]:/tmp$ gcc -O2 -fno-math-errno -o test -lm test.c && time 
./test
nan

real    0m7.521s
user    0m7.517s
sys     0m0.003s

Why did the answer turn into "nan"?

      Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting ltd.
http://www.lingnu.com/


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to