Previous Topic Next topic Print topic


Relational Operators

The relational operators and the operations they stand for are as follows:

Operators     Operations
= Equal
^= Not equal
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
^< Not less than (equivalent to >=)
^> Not greater than (equivalent to <=)
Note:

Open PL/I supports the use of a tilde (~) as an operator symbol equivalent to a caret (^).

The relational operators test the relationship of two operands. The result is always a Boolean value (a bit string of length 1). If the comparison is true, the resulting value is '1'B; if the comparison is false, the resulting value is '0'B. All relational operators are infix operators.

All operands used with relational operators must be scalar. If either operand is an arithmetic value or a pictured value, the operands are converted to a common arithmetic type as if they were operands of an add operator. If one operand is a pointer value and the other is an offset value, the offset is converted to a pointer, but only for = and ^= comparisons. In all other cases, the data types of the two operands must be equivalent.

When determining if two data types are equivalent, the ALIGNED, VARYING, RETURNS, UNALIGNED, VARIABLE, and string length attributes are ignored. Label, entry, file, and pointer data may be compared only for equality or inequality. Arithmetic and string data may be compared using any relational operator.

Arithmetic and pictured values are compared algebraically.

Character-string values are compared from left-to-right one character at a time until an inequality is found. The shorter value is effectively extended on the right with blank characters to make it the length of the longer value. Characters are compared using the collating sequence of the computer.

Bit-string values are compared from left-to-right one bit at a time until an inequality is found. The shorter value is effectively extended with zero bits on its right until it is the length of the longer value.

Pointer values are equal only if they address the same storage location.

Label and entry values are equal only if they designate the same statement and the same stack frame.

File values are equal only if they designate the same file control block.

Only comparisons of = and ^= are allowed for offset values. Area variables cannot be compared.

Wide character-string values are compared from left-to-right one wide character (or "byte-pair") at a time until an inequality is found. The shorter value is effectively extended on the right with blank characters (0x0020) to make it the length of the longer value. Characters are compared using the binary value of the byte-pair.

Previous Topic Next topic Print topic