On 01/16/2013 07:23 PM, David Paterson wrote:
-----Original Message-----
From: gcc-ow...@gcc.gnu.org [mailto:gcc-ow...@gcc.gnu.org] On Behalf
Of Mischa Baars
Sent: 16 January 2013 12:53
To: Robert Dewar; gcc@gcc.gnu.org
Subject: Re: not-a-number's

On 01/16/2013 01:28 PM, Robert Dewar wrote:
On 1/16/2013 7:10 AM, Mischa Baars wrote:

And as I have said before: if you are satisfied with the answer
'2', then so be it and you keep the compiler the way it is,
personally I'm am not able to accept changes to the sources anyway.
I don't think it is the right answer though.
The fact that you don't think that gcc shoudl follow the C standard
is hardly convincing unless it is backed up by convincing technical
argument. I see nothing surprising about the 2 here, indeed any
other answer *would* be surprising. I still don't understand the
basis for your non-stnadard views.
Mischa.

Let me explain again for you. Every 'if' statement in C is translated into a 
'fucom'
or similar instruction, which sets a number of conditions flags in the 
co-processor.
Some instructions need you to load these into the eflags register
manually, others don't.

Now, as soon as the 'fucom' or similar instruction encounters a
'signalling not-a- number' or 'quiet not-a-number' as one or both of
it's arguments, the condition code is set to 'not comparable'. This
has nothing to do with the C specification, but purely with the Intel/AMD 
hardware.
Intel and AMD aren't the only manufacturers or developers of floating
point hardware.  Plus there are software implementations to consider
as well.

In order for different hardware and software implementations to work
correctly with each other, there have to be standards defining all
aspects of their operation.  The same applies to the C language (and
other languages!).

Without standards we'd have no way to ensure programs would run in the
same way on different hardware, or when using different compilers...

If you ask me, it would be counter-intuitive to change the value of
the condition code to some other value and call that the new standard.
Instead it would seem logical to use the 'not comparable' and terminate the 'if'
statement.
What exactly do you mean by "terminate the if"??  Do you mean skip the
whole compound statement, including any "else" clause?
Yes, exactly. Skip it, including the 'else'.

Does that make sense to you?

In our example, a 'not-a-number' would be returned to the main
program, without the need for an extra 'isnan()'.
"...returned to the main program" doesn't make sense.  How is the
compiler going to figure out what to return and when?  What does it
return from a void, or int function?
There is an 'r = -NAN' at the beginning which will then be the value returned.

I'm sorry you don't like the way it's implemented, but we have
standards for very good reasons, and  although this particular one may
seem a bit counter- intuitive, it's well known, and many programs rely
on it operating as it does.

But, if you want to change the standards, by all means try...

David P.

Reply via email to