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.
| exclusive-disjunct-expr | is | exclusive-disjunct-expr .XORinclusive-disjunct-expr |
| less_greater_op | is | .LG. |
| or | <> | |
| not_op | is | .N. |
| and_op | is | .A. |
| or_op | is | .O. |
| exclusive_disjunct_op | is | .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.
| Intrinsic operator | Type of x1 | Type of x2 | Type of result |
|---|---|---|---|
| Unary +, - | I, R, Z, B, P | I, R, Z, I, P | |
| Binary +, -, *, /, ** | I | I, R, Z, B, P | I, R, Z, I, P |
| R | I, R, Z, B | R, R, Z, R | |
| Z | I, R, Z | Z, Z, Z | |
| B | I, R, B, P | I, R, B, P | |
| P | I, B, P | P, P, P | |
| (For Cray pointer, only + and - are allowed.) | |||
| // | C | C | C |
| .EQ., ==, .NE., /= | I | I, R, Z, B, P | L, L, L, L, L |
| R | I, R, Z, B, P | L, L, L, L, L | |
| Z | I, R, Z, B, P | L, L, L, L, L | |
| B | I, R, Z, B, P | L, L, L, L, L | |
| P | I, R, Z, B, P | L, L, L, L, L | |
| C | C | L | |
| .GT., >, .GE., >=, .LT., <, .LE., <= | I | I, R, B, P | L, L, L, L |
| R | I, R, B | L, L, L | |
| C | C | L | |
| P | I, P | L, L | |
| .LG., <> | R | R | L |
| .NOT. | L | L | |
| I, R, B | B | ||
| .AND., .OR., .EQV., .NEQV., .XOR. | L | L | L |
| I, R, B | I, R, B | B |
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.
| Operator category | Intrinsic operator | Operand types |
|---|---|---|
| Bitwise masking (Boolean) expressions | .NOT., .AND., .OR., .XOR., .EQV., .NEQV. | Integer, real, typeless, or Cray pointer. |
| x1 x2Expressions_and_Assignment.html#concept_pr1_jht_2s__ID-374-00002a111 | Integer | Real | Boolean | Pointer | Logical | Character |
|---|---|---|---|---|---|---|
| Integer | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Not valid | Not valid2 |
| Real | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Not valid | Not valid2 |
| Boolean | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Not valid | Not valid2 |
| Pointer | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Masking, operation, Boolean result. | Not valid | Not valid2 |
| Logical | Not valid2 | Not valid2 | Not valid2 | Not valid2 | Logical operation logical results | Not valid2 |
| Character | Not valid2 | Not valid2 | Not valid2 | Not valid2 | Not valid | Not 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.
.NOT. 1100 1100 1100 1100 1100
=0011 .AND. 1010 .OR. 1010 .XOR. 1010 .EQV. 1010
---- ---- ---- ----
1000 1110 0110 1001Assignment
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.
x1 and x2 represent operands for a logical or bitwise expression, using operators .NOT., .AND., .OR., .XOR., .NEQV., and .EQV..
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.