not-a-number's
Mischa Baars
mjbaars1977@gmail.com
Wed Jan 16 11:55:00 GMT 2013
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.
>
> 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.
And indeed apparently the answer then is '2'. However, I don't think
this is correct. If that means that there is an error in the C
specification, then there probably is an error in the specification.
>
> So:
>
> {
> double r = -NAN;
>
> // if (!isnan(y) && !isnan(x))
> // {
> double a = absd(x);
> double b = absd(y);
>
> if (b != a)
>
> 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.
More information about the Gcc
mailing list