Reputation: 103
I'm wondering where I can find the standard output (if there is one) when comparing (LT & GT) 2 special single precision IEEE-754 floating point values, being combinations of -inf/+inf/NaN/-0/+0.
I wrote a test program and it gave me following output, but how to check if it is compliant?:
Upvotes: 1
Views: 1125
Reputation: 223553
The relevant portion of the IEEE 754-2008 standard, and a late 754-2019 draft, is:
Four mutually exclusive relations are possible: less than, equal, greater than, and unordered. The last case arises when at least one operand is NaN. Every NaN shall compare unordered with everything, including itself. Comparisons shall ignore the sign of zero (so +0 = −0). Infinite operands of the same sign shall compare equal.
From this, we see that none of the comparisons with a NaN would yield less than or greater than, and therefore any test of less than or greater than should yield false, so the results in the table conform in this regard.
Similarly, the comparisons of an infinity to the same infinity and of either zero to either zero should yield false, so the table conforms in this regard too.
The standard does not explicitly detail comparisons of other values; they are inherited from ordinary arithmetic, and we can see the table conforms in this regard too.
See the links in the Standards section of the Wikipedia IEEE 754 page for sources for official versions of the standard.
Upvotes: 3
Reputation:
The standard says:
nan
comparisons are always evaluated as false (even nan == nan
)+inf > x
is true if x
is neither +inf
nor nan
, and false otherwise-inf < x
is true if x
is neither -inf
nor nan
, and false otherwiseUpvotes: 2