FORTRAN Logical Operators

Home Computational Physics FORTRAN FORTRAN Logical Operators


Logical Operators

The logical operators are:
Logical Operators.
Logical Operators
OperatorRepresenting
.NOT.Logical Negation
.AND.Logical Conjunction
.OR.Logical Inclusive Disjunction
.EQV.Logical Equivalence
.NEQV.Logical Nonequivalence


Form and Interpretation of Logical Expressions.
A set of formation rules is used to establish the interpretation of a logical expression that contains two or more logical operators. There is a precedence among the logical operators, which determines the order in which the operands are to be combined unless the order is changed by the use of parentheses. The precedence of the logical operators is as follows:

Form and Interpretation of Logical Expressions
Logical Expressions
OperatorRepresenting
.NOT.Highest
.AND. 
.OR. 
.EQV. or .NEQV.Lowest


For example, in the expression
A .OR. B .AND. C

the .AND. operator has higher precedence than the .OR. operator; therefore, the interpretation of the above expression is the same as the interpretation of the expression

A .OR. (B .AND. C)


Value of Logical Factors, Terms, Disjuncts, and Expressions.
The value of a logical factor involving .NOT. Is shown below:
Logical factor involving .NOT.
Logic 1.NOT. (Logic 1)
TRUEFALSE
FALSETRUE


The value of a logical term involving .AND. is shown below:

Logical factor involving .AND.
Logic 1Logic 2(Logic 1) .AND. (Logic 2)
TRUETRUETRUE
TRUEFALSEFALSE
FALSETRUEFALSE
FALSEFALSEFALSE


The value of a logical term involving .OR. is shown below:

Logical factor involving .OR.
Logic 1Logic 2(Logic 1) .OR. (Logic 2)
TRUETRUETRUE
TRUEFALSETRUE
FALSETRUETRUE
FALSEFALSEFALSE


The value of a logical term involving .EQV. is shown below:

Logical factor involving .EQV.
Logic 1Logic 2(Logic 1) .EQV. (Logic 2)
TRUETRUETRUE
TRUEFALSEFALSE
FALSETRUEFALSE
FALSEFALSETRUE


The value of a logical term involving .NEQV. is shown below:

Logical factor involving .NEQV.
Logic 1Logic 2(Logic 1) .NEQV. (Logic 2)
TRUETRUEFALSE
TRUEFALSETRUE
FALSETRUETRUE
FALSEFALSEFALSE