Important: The information in this document is obsolete and should not be used for new development.
Comparisons
PowerPC Numerics supports the usual numeric comparisons: less than, less than or equal to, greater than, greater than or equal to, equal to, and not equal to (see Table 6-1 for a complete listing). For real numbers, these comparisons behave according to the familiar ordering of real numbers.Comparisons With NaNs and Infinities
Numeric comparisons handle NaNs and Infinities as well as real numbers. The usual trichotomy for real numbers is extended so that, for any numeric values a and b, exactly one of the following statements is true:
The following rule determines which statement is true: If a or b is a NaN, then a and b are unordered; otherwise, a is less than, equal to, or greater than b according to the ordering of the real numbers, with the understanding that
- a < b
- a > b
- a = b
- a and b are unordered
Comparison Operators
The meaning of high-level language relational operators is a natural extension of their old meaning based on trichotomy. For example, the C expression is true if x is less than y or if x equals y, and is false if x is greater than y or if x and y are unordered. Note that the numeric not-equal relation means less than, greater than, or unordered. The FPCE technical report extends the usual set of C relational operators to a set of 14 comparisons, shown in Table 6-1.Some relational operators in high-level language comparisons contain the predicate less than or greater than, but not unordered. In C, those relational operators are
<
,<=
,>
, and>=
(but not==
and!=
). For those relations, comparisons signal invalid if the operands are unordered, that is, if either operand is a NaN. For the operators equal and nonequal, comparisons with NaN are not misleading; thus, when x or y is a NaN, the relation x == y is false, which is not misleading. Likewise, when x or y is a NaN, x != y returns true, again not misleading. On the other hand, when x or y is a NaN, x < y being false might tempt you to conclude that x y, so PowerPC Numerics signals invalid to help you avoid the pitfall. Table 6-1 shows the results of such comparisons in C.The full 26 distinct comparison predicates of the IEEE standard may be obtained by logical negation of all of the operators except for == and !=, which never signal invalid. For example, (x < y) and !(x !< y) are logically equivalent for all possible values of a and b, but the former raises the invalid exception flag when x and y compare unordered while the latter does not.
A comparison with a signaling NaN as an operand always signals invalid, just as in arithmetic operations.
In addition to the comparison operators, there are also library functions that perform comparisons. See "Comparison Functions" in Chapter 10, "Transcendental Functions."