Expressions and Assignment
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.
Rules for Forming Expressions
The Cray Fortran compiler supports exclusive disjunct expressions of the form:
|
|
|
|
||
|
Intrinsic and Defined Operations
Cray supports the following intrinsic operators as extensions:
|
|
|
|---|---|---|
|
|
|
|
|
|
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 no longer allows abbreviations for logical and masking operators. The abbreviations .A., .O., .N., and .X. are no longer synonyms for .AND., .OR., .NOT., and .XOR., respectively. This change does not affect user-defined operators and operator overloads; therefore, users can create user-defined operators to behave as shorthand operators.
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 Operations
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.
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 |
Arithmetic operator (the binary +, -, *, /, and **) followed by Unary operator (+ or -, before the second operand) is allowed. This is an extension to the Fortran standard.
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.
Bitwise Logical Expressions
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.
Operator category |
Intrinsic operator |
Operand 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).
x1 x2 |
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 valid** |
Real |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Not valid |
Not valid** |
Boolean |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Not valid |
Not valid** |
Pointer |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Masking, operation, Boolean result. |
Not valid |
Not valid** |
Logical |
Not valid** |
Not valid** |
Not valid** |
Not valid** |
Logical operation, logical results |
Not valid** |
Character |
Not valid** |
Not valid** |
Not valid** |
Not valid** |
Not valid |
Not valid** |
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.
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.
Array Reference
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 messages.