DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Floating point operations

Compares and unordered condition

In addition to the usual relationships between floating point values (less than, equal, greater than), there is a fourth relationship: unordered. The unordered case arises when at least one operand is a NaN. Every NaN compares unordered with any value, including itself.

The C compilation system provides the following predicates required by IEEE between floating point operands:

== >=
!= <
> <=

While there is no predicate to test for unordered, you can use isnand or isnanf to test whether an argument is a NaN. For information on isnand and isnanf, see isnan(3C).

The relations >, >=, <, and <= raise invalid operation for unordered operands. The compiler generated code does not guard against the unordered outcome of a comparison. If the trap is masked, the path taken for unordered conditions is the same as if the conditional were true, which may result in incorrect behavior.

For the predicates == and !=, unordered condition does not lead to invalid operation. The path taken for unordered condition is the same as when the operands are non-equal, which is correct.

(a > b) is not the same as ( !(a <= b) ) in IEEE floating point arithmetic. The difference occurs when b or a compares unordered. The C compiler generates the same code for both cases.


Previous topic: Square root

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004