Anatoly Vorobey wrote:
If you declare it with
double q = 0;, you will get a meaningful answer in the -fno-math-errno
case as well.
Thanks, that was it, sort of:
[EMAIL PROTECTED]:/tmp$ cat test.c
#include <stdio.h>
#include <math.h>
int
main(int argc, char **argv)
{
long long i;
double q=0;
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.985s
sys 0m0.001s
[EMAIL PROTECTED]:/tmp$ gcc -O1 -o test -lm test.c && time ./test
21081849486.439274
real 0m0.770s
user 0m0.769s
sys 0m0.002s
[EMAIL PROTECTED]:/tmp$ gcc -O2 -o test -lm test.c && time ./test
21081849486.439274
real 0m0.767s
user 0m0.765s
sys 0m0.001s
[EMAIL PROTECTED]:/tmp$ gcc -O2 -fno-math-errno -o test -lm test.c && time
./test
21081849486.442493
real 0m0.687s
user 0m0.685s
sys 0m0.001s
While the results are definitely close, they are not identical. Now, I
may not wish to say anything about an error that is 12 orders of
magnitude smaller than the actual number, but if memory serves me right,
this should be within the double precision.
It may well be that the optimization reordered something here, which
caused the difference in numerical errors. Still, I would like a "second
opinion" :-).
And, as noted earlier, this has nothing to do with what I'm seeking,
which is *integer* calculations, not floating point.
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]