On Mon, Aug 08, 2005 at 09:30:18PM +0300, Shachar Shemesh wrote:
> Actually, something extremely weird it going on here. The result change, 
> considerably, when I compile with or without "no-math-errno":

Yeah. The no-math-errno thing seems to trigger quite a few FPU-related
optimizations.

> >[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"?

Because the variable q is garbage when the loop starts, and ends up
being either garbage or overflown. Without -fno-math-errno, it's 
initialised to 0 before the loop begins. If you declare it with 
double q = 0;, you will get a meaningful answer in the -fno-math-errno
case as well.

The compiler isn't at fault here because it doesn't have to initialize it 
for you.

-- 
avva
"There's nothing simply good, nor ill alone" -- John Donne


=================================================================
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