Expressions and Assignment

In Fortran, calculations are specified by writing expressions. Expressions look much like algebraic formulas in mathematics, particularly when the expressions involve calculations on numerical values.

Expressions

In Fortran, calculations are specified by writing expressions. Expressions look much like algebraic formulas in mathematics, particularly when the expressions involve calculations on numerical values.

Expressions often involve nonnumeric values, such as character strings, logical values, or structures; these also can be considered to be formulas that involve nonnumeric quantities rather than numeric ones.

The Cray Fortran compiler supports exclusive disjunct expressions of the form:
exclusive-disjunct-exprisexclusive-disjunct-expr .XORinclusive-disjunct-expr
Cray supports the following intrinsic operators as extensions:
less_greater_opis.LG.
or<>
not_opis.N.
and_opis.A.
or_opis.O.
exclusive_disjunct_opis.XOR.
or.X.

The Cray Fortran less than or greater than intrinsic operation is represented by the <> operator and the .LG. keyword. This operation is suggested by the IEEE standard for floating-point arithmetic, and the Cray Fortran compiler supports this operator. Only values of type real can appear on either side of the <> or .LG. operators. If the operands are not of the same kind type value, the compiler converts them to equivalent kind types. The <> and .LG. operators perform a less-than-or-greater-than operation as specified in the IEEE standard for floating-point arithmetic.

The Cray Fortran compiler allows abbreviations for the logical and masking operators. The abbreviations .A., .O., .N., and .X. are synonyms for .AND., .OR., .NOT., and .XOR., respectively.

The masking of Boolean operators and their abbreviations, which are extensions to Fortran, can be redefined as defined operators. If a masking operator is redefined, the definition overrides the intrinsic masking operator definition. See Bitwise Logical Expressions for a list of the operators.

In the following table, the symbols I, R, Z, C, L, B, and P stand for the types integer, real, complex, character, logical, Boolean, and Cray pointer, respectively. Where more than one type for x2 is given, the type of the result of the operation is given in the same relative position in the next column. Boolean and Cray pointer types are extensions of the Fortran standard.
Table 1. Operand Types and Results for Intrinsic Operations
Intrinsic operatorType of x1Type of x2Type of result
Unary +, -I, R, Z, B, PI, R, Z, I, P
Binary +, -, *, /, **II, R, Z, B, PI, R, Z, I, P
RI, R, Z, BR, R, Z, R
ZI, R, ZZ, Z, Z
BI, R, B, PI, R, B, P
PI, B, PP, P, P
(For Cray pointer, only + and - are allowed.)
//CCC
.EQ., ==, .NE., /=II, R, Z, B, PL, L, L, L, L
RI, R, Z, B, PL, L, L, L, L
ZI, R, Z, B, PL, L, L, L, L
BI, R, Z, B, PL, L, L, L, L
PI, R, Z, B, PL, L, L, L, L
CCL
.GT., >, .GE., >=, .LT., <, .LE., <=II, R, B, PL, L, L, L
RI, R, BL, L, L
CCL
PI, PL, L
.LG., <>RRL
.NOT.LL
I, R, BB
.AND., .OR., .EQV., .NEQV., .XOR.LLL
I, R, BI, R, BB

The operators .NOT., .AND., .OR., .EQV., and .XOR. can also be used in the Cray Fortran compiler's bitwise masking expressions; these are extensions to the Fortran standard. The result is Boolean (or typeless) and has no kind type parameters.

A bitwise logical expression (also called a masking expression) is an expression in which a logical operator operates on individual bits within integer, real, Cray pointer, or Boolean operands, giving a result of type Boolean. Each operand is treated as a single storage unit. The result is a single storage unit, which is either 32 or 64 bits depending on the -s option specified during compilation. Boolean values and bitwise logical expressions use the same operators but are different from logical values and expressions.
Table 2. Cray Fortran Intrinsic Bitwise Operators and the Allowed Types of their Operands
Operator categoryIntrinsic operatorOperand types
Bitwise masking (Boolean) expressions.NOT., .AND., .OR., .XOR., .EQV., .NEQV.Integer, real, typeless, or Cray pointer.
Bitwise logical operators can also be written as functions; for example A .AND. B can be written as IAND(A,B) and .NOT. A can be written as NOT(A).
Table 3. Data Types in Bitwise Logical Operations
x1 x2Expressions_and_Assignment.html#concept_pr1_jht_2s__ID-374-00002a111IntegerRealBooleanPointerLogicalCharacter
IntegerMasking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Not validNot valid2
RealMasking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Not validNot valid2
BooleanMasking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Not validNot valid2
PointerMasking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Masking, operation, Boolean result.Not validNot valid2
LogicalNot valid2Not valid2Not valid2Not valid2Logical operation logical resultsNot valid2
CharacterNot valid2Not valid2Not valid2Not valid2Not validNot valid2

Bitwise logical expressions can be combined with expressions of Boolean or other types by using arithmetic, relational, and logical operators. Evaluation of an arithmetic or relational operator processes a bitwise logical expression with no type conversion. Boolean data is never automatically converted to another type.

A bitwise logical expression performs the indicated logical operation separately on each bit. The interpretation of individual bits in bitwise multiplication-exprs, summation-exprs, and general expressions is the same as for logical expressions. The results of binary 1 and 0 correspond to the logical results TRUE and FALSE, respectively, in each of the bit positions. These values are summarized as follows:
.NOT. 1100            1100           1100           1100           1100
     =0011      .AND. 1010      .OR. 1010     .XOR. 1010     .EQV. 1010
                      ----           ----           ----           ----
                      1000           1110           0110           1001

Assignment

The Cray Fortran compiler supports Boolean and Cray pointer intrinsic assignments. The Cray Fortran compiler supports type Boolean or BOZ constants in assignment statements in which the variable is of type integer or real. The bits specified by the constant are moved into the variable with no type conversion.

The Cray Fortran compiler allows arrays to be referenced with fewer than the declared number of dimensions. The subscripts specified in the array reference are used for the leftmost dimensions, and the lower bounds are used for the rightmost subscripts that were omitted. This extension to the Fortran standard applies to both arrays and coarrays.

When the option to note deviations from the Fortran standard is in effect (-en), this type of an array reference will cause compilation errors.

1

x1 and x2 represent operands for a logical or bitwise expression, using operators .NOT., .AND., .OR., .XOR., .NEQV., and .EQV..

2

Indicates that if the operand is a character operand of 32 or fewer characters, the operand is treated as a Hollerith constant and is allowed.