A relational expression yields a logical value of either .TRUE. or .FALSE. on evaluation and comparison of two arithmetic expressions or two character expressions. A relational expression can appear only within a logical expression.
Table below lists the Fortran relational operators. Arithmetic and character operators are evaluated before relational operators.
Table: Fortran Relational Operators
The operands of a relational operator can be arithmetic or character expressions. The relational expression requires exactly two operands and is written in the following form:
Note: Both e1 and e2 must be the same type of expression, either arithmetic or character.
The result of a relational expression is of type logical, with a value of .TRUE. or .FALSE.. The manner in which the expression is evaluated depends onthe data type of the operands.
Arithmetic Relational Expressions
In an arithmetic relational expression, e1 and e2 must each be an integer, real, double precision, complex, or double complex expression. relop must be a relational operator.
The following are examples of arithmetic relational expressions:(a + b) .EQ. (c + 1)
You can use complex type operands only when specifying either the .EQ. or .NE. relational operator.
An arithmetic relational expression has the logical value .TRUE. only if the values of the operands satisfy the relation specified by the operator.
Otherwise, the value is .FALSE..
If the two arithmetic expressions e1 and e2 differ in type, the expression is evaluated as follows:
where the value 0 (zero) is of the same type as the expression ((e1)- (e2)) and the type conversion rules apply to the expression. Do not compare a double precision value with a complex value.
Character Relational Expressions
In a character relational expression, e1 and e2 are character expressions and relop is a relational operator.
The following is an example of a character relational expression:NAME .EQ. 'HOMER'
A character relational expression has the logical value .TRUE. only if the values of the operands satisfy the relation specified by the operator. Otherwise, the value is .FALSE..
The result of a character relational expression depends on the collating sequence as follows:
The collating sequence depends partially on the processor; however, equality tests .EQ. and .NE. do not depend on the processor collating sequence and can be used on any processor.
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.