FORTRAN Reference Manual

Expressions
FORTRAN Reference Manual528615-001
3-8
Evaluation of Relational Expressions
In the following example, if the integer variables J and K have a value of 1 and 100
respectively, the relational expressions have the indicated values:
j .GT. k <-- 1 .GT. 100 is false
k .GT. j <-- 100 .GT. 1 is true
k .GE. j <-- 100. GE. 1 is true
Evaluation of Relational Expressions
If a relational arithmetic expression contains operands of different types, FORTRAN
converts the lower ranking data type to the higher ranking data type before comparing
the operands.
A character string X is less than a character string Y if, starting at the left end of both
strings, the first character in X that is not equal to the corresponding character in Y is
less than the character in Y in the ASCII collating sequence. Similarly, a character
string X is greater than a character string Y if, starting at the left end of both strings, the
first character in X that is not equal to the corresponding character in Y is greater than
the character in Y in the ASCII collating sequence.
If the character expressions being compared are different lengths, FORTRAN pads the
shorter expression with trailing blanks until it is equal in length to the longer
expression.
Considerations
You cannot compare a COMPLEX value and a DOUBLE PRECISION value.
You can use a COMPLEX value in an arithmetic relational expression only if the
relational operator is .EQ. or .NE..
The following examples include valid relational expressions:
LOGICAL a, b
COMPLEX x, y
READ (*,*) w, x, y, z
a = x .EQ. y
b = w .GE. z
CHARACTER * 10 a, b
LOGICAL order
READ (*,*) a, b
order = a .GT. b