Comparison operations
A
comparison operation is specified by combining operands with one
of the following infix operators:
The result of a comparison operation is always a bit string of length 1.
The value is '1'B if the relationship is true,
or '0'B if the relationship is false.
Comparisons are defined as follows:
- Algebraic
- is the comparison
of signed arithmetic values in coded arithmetic form. If operands
differ in base, scale, precision, or mode, they are converted in
a manner analogous to arithmetic operation conversions. Numeric
character data is converted to coded arithmetic before comparison.
Only the operators = and ¬= are valid for comparison
of operands that are complex numbers.
- Character
- is a left-to-right,
character-by-character comparison of characters according to the
binary value of the bytes.
- Bit
- is a left-to-right, bit-by-bit
comparison of binary digits.
- Graphic
- is a left-to-right, symbol-by-symbol
comparison of DBCS characters. The comparison is based on the binary
values of the DBCS characters.
- Widechar
- is a left-to-right, widechar-by-widechar
comparison of characters according to the binary value of the byte-pairs.
- Ordinal data
- is a comparison of ordinals of the same type using relational operators.
- Pointer and offset data
- is a comparison of pointer and offset values containing any
relational operators. However, the only conversion that can take
place is offset to pointer.
- Program-control data
- is a comparison of the internal coded forms
of the operands. Only the comparison operators = and ¬= are
allowed; area variables cannot be compared. No type conversion can
take place; all type differences between operands for program-control
data comparisons are in error.
Comparisons are equal for the following operands:
- Entry
- In a comparison operation, it is not an error to specify an
entry variable whose value is an entry point of an inactive block.
Entry names on the same PROCEDURE or ENTRY statement do not compare equal.
- Format
- Format labels on the same FORMAT statement compare equal.
- File
- If the operands represent file values, all of whose parts
are equal.
- Label
- Labels on the same statement compare equal. In a comparison
operation, it is not an error to specify a label variable whose
value is a label constant used in a block that is no longer active.
The label on a compound statement does not compare equal with
that on any label contained in the body of the compound statement.
If the operands of a computational data comparison have data
types that are appropriate to different types of comparison, the
operand of the lower precedence is converted to conform to the comparison
type of the other. The precedence of comparison types is (1) algebraic
(highest), (2) widechar, (3) graphic, (4) character, (5) bit. For
example, if a bit string is compared with a fixed decimal value,
the bit string is converted to fixed binary for algebraic comparison
with the decimal value. The decimal value is also converted to fixed
binary.
In the comparison of strings of unequal lengths, the shorter
string is padded on the right. This padding consists of:
- Blanks in a character comparison
- '0'B in a bit comparison
- A graphic (DBCS) blank in a graphic comparison.
- A widechar blank ('0020'wx) in a widechar comparison.
The following example shows a comparison operation in an IF statement:
if A = B
then action-if-true;
else action-if-false;
The evaluation of the expression A = B yields either '1'B, for true, or '0'B, for false.
In the following assignment statement:
X = A <= B;
the value '1'B is assigned to X if A is less than B; otherwise, the value '0'B is assigned.
In the following assignment statement:
X = A = B;
the first equal symbol is the assignment symbol; the second equal
symbol is the comparison operator. The value '1'B is assigned to X if A is equal to B; otherwise, the value '0'B is assigned.
An example of comparisons in an arithmetic expression is:
(X<0)*A + (0<=X & X<=100)*B + (100<X)*C
The value of the expression is A, B, or C and is determined by the value of X.
|
This information center is powered by Eclipse technology. (http://www.eclipse.org)