This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: not-a-number's


On 01/16/2013 12:07 PM, Andrew Haley wrote:
On 01/16/2013 09:27 AM, Mischa Baars wrote:
On 01/16/2013 10:06 AM, Andreas Schwab wrote:
Mischa Baars <mjbaars1977@gmail.com> writes:

This means that the first 'if' statement should have been terminated when
There is no such thing as a "terminated statement".  The first condition
evaluates to true.
Whatever you want, although personally I think it is very unlikely that
'2' is the correct value to return :)
Let's go through this line by line.  If there's anything you disagree
with, speak up.  But if you disagree that GCC has implemented C
correctly according to the standard, you must quote the relevant
sections of the document and explain your belief, not in terms of what
you think it should do, but in terms of what the standard actually
says.

Comparisons with NaN don't terminate a statement, and they don't
return a NaN.  They return a boolean.
They shouldn't return anything, the comparison should be terminated.

Here's what Standard C, F.8.3 Relational operators, says:


x != x â false The statement x != x is true if x is a NaN.

x == x â true The statement x == x is false if x is a NaN.

So:

{
     double r = -NAN;
This should be the value returned.

// if (!isnan(y) && !isnan(x)) // { double a = absd(x); double b = absd(y);

if (b != a)
Right here evaluation should be terminated, when one or both of the arguments are NaN. The statement becomes invalid.

If one of a or b is a NaN, the comparison is unordered, so we take this branch.


         {
             if (b < a)

If one of a or b is a NaN, the comparison is unordered, so it returns
false.  We'll take the else branch.

             {
                 if (b != 0)                             // octant 1, 4, 5 and 8 (open set)
                 {
                     r = 0;
                 }
                 else                                    // x-axis
                 {
                     r = 1;
                 }
             }
             else
             {
                 if (a != 0)                             // octant 2, 3, 6 and 7 (open set)

If a is a NaN, the comparison is unordered, so != returns true.  So we
take this branch and return 2.

                 {
                     r = 2;                              // not-a-number's ???
                 }
                 else                                    // y-axis
                 {
                     r = 3;
                 }
             }
         }
         else                                            // between axes
         {
             r = 4;
         }
//  }

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]