unordered comparisons

Tom MacDonald uunet!fig.cray.com!tam
Wed Dec 4 22:12:26 PST 1991


I've already expressed my concerns about the new comparison
operators at NCEG meetings several times so I don't want to
belabor that point.  I would point out though that the
operator precedence needs to be spelled out.  For instance,
does !<>= have the same precedence as the equality operators
(==  !=) or the relational operators (< <= > >=)?  Perhaps
a new level of operator precedence is needed because unordered
is different from the mathematical comparisons of less-than,
equal-to, and greater-than.

I have been involved with trying to add a `complex' type to C.
At the last NCEG meeting a question was raised about the
meaning of these new operators with respect to complex values.

Currently the only comparison operators allowed to have
complex operands are the equality operators:

	==    !=

If the imaginary part of one complex number is a NaN, then does
that imply that the two complex numbers do not compare equal?
I suspect the answer is "they do not compare equal."  If that
is the case then should the

	!<>=   !<>

operators be allowed to have complex operands?  Since !<>=
is TRUE if the comparison is unordered then the result is
TRUE is either the real or imaginary parts are NaNs for either
operand.  Perhaps the <>= operator should also be permitted
since it is the complement of !<>= just like == is the complement
of !=.

The point is that the notion of unordered needs to be defined
for complex numbers as well.  Is it sufficient to know that
a NaN exists somewhere?  The case:

	z != z

will not tell you whether the NaN is in the real part, imaginary part,
or both parts.

There was also a proposal from Kahan to allow relational operators
to have complex operands.  For example:

	#include <complex.h>

	double complex z1, z2;

	. . .

	if (z1 < z2) {
	   . . .
	}

The "z1 < z2" comparison evaluates to true iff:

	 cimag(z1) == cimag(z2)  and  creal(z1) < creal(z2)

I used the word `and' because I'm not sure if it is suppose to be
the && operator or the & operator.  Does this comparison short
circuit if the imaginary parts do not compare equal?  This could
matter if signaling NaNs are present.

The NCEG "Floating-Point C Extensions" document states that

	a < b

raises the invalid exception if the operands compare unordered.
However,

	a == b

never raises the invalid exception (even if the operands are unordered).
Does this mean that

	z1 < z2

only raises the invalid exception if the real parts compare unordered?

In general I'm interested in what kinds of comparisons are felt to
be useful with complex numbers and would appreciate any input others
may have.

I've been working with Fortran some lately and I just wondered
about the arithmetic IF.  The Fortran-77 spec. states that

	IF (e) 10, 20, 30

causes control to transfer to 10 if e<0, 20 if e=0, and 30 if e>0.
If `e' is a real expression that evaluates unordered, then what
happens?  None of the conditions are satisfied.  I'm sure someone
has bumped into this before.  Is there any proposed solution?

enquiring-minds-want-to-know-ly yours,

Tom MacDonald



More information about the Numeric-interest mailing list