The simplest form of an arithmetic expression is an unsigned arithmetic constant, symbolic name of an arithmetic constant, arithmetic variable reference, arithmetic array element reference, or arithmetic function reference. More complicated arithmetic expressions may be formed by using one or more arithmetic operands together with arithmetic operators and parentheses. Arithmetic operands must identify values of type integer, real, double precision, or complex.

______________________________________ | | | | Operator | Representing | |__________|_________________________| | | | | ** | Exponentiation | | / | Division | | * | Multiplication | | - | Subtraction or Negation | | + | Addition or Identity | |__________|_________________________|

Each of the operators **, /, and * operates on a pair of operands and is written between the two operands. Each of the operators + and - either:

- operates on a pair of operands and is written between the two operands, or
- operates on a single operand and is written preceding that operand.

_____________________________________________________ | | | | Use of Operator | Interpretation | |_________________|_________________________________| | | | | x ** x | Exponentiate x to the power x | | 1 2 | 1 2 | | x / x | Divide x by x | | 1 2 | 1 2 | | x * x | Multiply x and x | | 1 2 | 1 2 | | x - x | Subtract x from x | | 1 2 | 2 1 | | - x | Negate x | | 2 | 2 | | x + x | Add x and x | | 1 2 | 1 2 | | + x | Same as x | | 2 | 2 | |_________________|_________________________________|where:

- x
_{1}denotes the operand to the left of the operator - x
_{2}denotes the operand to the right of the operator

The interpretation of a division may depend on the data types of the operands (6.1.5).

A set of formation rules is used to establish the interpretation of an arithmetic expression that contains two or more operators. There is a precedence among the arithmetic 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 arithmetic operators is as follows:

___________________________ | | | | Operator | Precedence | |__________|______________| | | | | ** | Highest | | * and / | Intermediate | | + and - | Lowest | |__________|______________|

For example, in the expression

- A ** 2

the exponentiation operator (**) has precedence over the negation operator (-); therefore, the operands of the exponentiation operator are combined to form an expression that is used as the operand of the negation operator. The interpretation of the above expression is the same as the interpretation of the expression

- (A ** 2)

The *arithmetic operands* are:

- Primary
- Factor
- Term
- Arithmetic expression

The formation rules to be applied in establishing the interpretation of arithmetic expressions are in 6.1.2.1 through 6.1.2.4.

- Unsigned arithmetic constant (4.2.3)
- Symbolic name of an arithmetic constant (8.6)
- Arithmetic variable reference (2.5)
- Arithmetic array element reference (5.3)
- Arithmetic function reference (15.2)
- Arithmetic expression enclosed in parentheses (6.1.2.4)

- Primary
- Primary ** factor

Thus, a factor is formed from a sequence of one or more primaries separated by the exponentiation operator. Form (2) indicates that in interpreting a factor containing two or more exponentiation operators, the primaries are combined from right to left. For example, the factor

2**3**2

has the same interpretation as the factor

2**(3**2)

- Factor
- Term / factor
- Term * factor

Thus, a term is formed from a sequence of one or more factors separated by either the multiplication operator or the division operator. Forms (2) and (3) indicate that in interpreting a term containing two or more multiplication or division operators, the factors are combined from left to right.

- Term
- + term
- - term
- Arithmetic expression + term
- Arithmetic expression - term

Thus, an arithmetic expression is formed from a sequence of one or more terms separated by either the addition operator or the subtraction operator. The first term in an arithmetic expression may be preceded by the identity or the negation operator. Forms (4) and (5) indicate that in interpreting an arithmetic expression containing two or more addition or subtraction operators, the terms are combined from left to right.

Note that these formation rules do not permit expressions containing two consecutive arithmetic operators, such as A**-B or A+-B. However, expressions such as A**(-B) and A+(-B) are permitted.

The following are examples of integer constant expressions:

3 -3 -3+4

*Integer expressions, real expressions, double precision expressions,* and *complex expressions* are arithmetic expressions whose values are of type integer, real, double precision, and complex, respectively.

When the operator + or - operates on a single operand, the data type of the resulting expression is the same as the data type of the operand.

When an arithmetic operator operates on a pair of operands, the data type of the resulting expression is given in Tables 2 and 3. In these tables, each letter I, R, D, or C represents an operand or result of type integer, real, double precision, or complex, respectively.

The type of the result is indicated by the I, R, D, or C that precedes the equals, and the interpretation is indicated by the expression to the right of the equals. REAL, DBLE, and CMPLX are the type-conversion functions described in 15.10.

____________________________________________________________ | x | | | | x 2 | I | R | | 1 | 2 | 2 | |______|__________________________|________________________| | | | | | I | I = I + I | R = REAL(I ) + R | | 1 | 1 2 | 1 2 | | R | R = R + REAL(I ) | R = R + R | | 1 | 1 2 | 1 2 | | D | D = D + DBLE(I ) | D = D + DBLE(R ) | | 1 | 1 2 | 1 2 | | C | C=C +CMPLX(REAL(I ),0.) | C = C + CMPLX(R ,0.) | | 1 | 1 2 | 1 2 | |______|__________________________|________________________| ____________________________________________________________ | x | | | | x 2 | D | C | | 1 | 2 | 2 | |_______|______________________|___________________________| | | | | | I | D = DBLE(I ) + D | C=CMPLX(REAL(I ),0.)+C | | 1 | 2 2 | 2 2 | | R | D = DBLE(R ) + D | C = CMPLX(R ,0.) + C | | 1 | 1 2 | 1 2 | | D | D = D + D | Prohibited | | 1 | 1 2 | | | C | Prohibited | C = C + C | | 1 | | 1 2 | |_______|______________________|___________________________|

Tables giving the type and interpretation of expressions involving -, *, and / may be obtained by replacing all occurrences of + in Table 2 by -, *, or /, respectively.

____________________________________________________________ | x | | | | x 2 | I | R | | 1 | 2 | 2 | |__________|___________________|___________________________| | | | | | I | I = I **I | R = REAL(I )**R | | 1 | 1 2 | 1 2 | | R | R = R **I | R = R **R | | 1 | 1 2 | 1 2 | | D | D = D **I | D = D **DBLE(R ) | | 1 | 1 2 | 1 2 | | C | C = C **I | C = C **CMPLX(R ,0.) | | 1 | 1 2 | 1 2 | |__________|___________________|___________________________| ____________________________________________________________ | x | | | | x 2 | D | C | | 1 | 2 | 2 | |_______|_____________________|____________________________| | | | | | I | D = DBLE(I )**D | C=CMPLX(REAL(I ),0.)**C | | 2 | 2 2 | 2 2 | | R | D = DBLE(R )**D | C = CMPLX(R ,0.)**C | | 1 | 1 2 | 1 2 | | D | D = D **D | Prohibited | | 1 | 1 2 | | | C | Prohibited | C = C **C | | 1 | | 1 2 | |_______|_____________________|____________________________|

Four entries in Table 3 specify an interpretation to be a complex value raised to a complex power. In these cases, the value of the expression is the "principal value" determined by x_{1}**x_{2} = EXP(x_{2}*LOG(x_{1})), where EXP and LOG are functions described in 15.10.

Except for a value raised to an integer power, Tables 2 and 3 specify that if two operands are of different type, the operand that differs in type from the result of the operation is converted to the type of the result and then the operator operates on a pair of operands of the same type. When a primary of type real, double precision, or complex is raised to an integer power, the integer operand need not be converted. If the value of I_{2} is negative, the interpretation of I_{1}**I_{2} is the same as the interpretation of 1/(I_{1}**ABS(I_{2})), which is subject to the rules for integer division (6.1.5). For example, 2**(-3) has the value of 1/(2**3), which is zero.

The type and interpretation of an expression that consists of an operator operating on either a single operand or a pair of operands are independent of the context in which the expression appears. In particular, the type and interpretation of such an expression are independent of the type of any other operand of any larger expression in which it appears. For example, if X is of type real, J is of type integer, and INT is the real-to-integer conversion function, the expression INT(X+J) is an integer expression and X+J is a real expression.

The simplest form of a character expression is a character constant, symbolic name of a character constant, character variable reference, character array element reference, character substring reference, or character function reference. More complicated character expressions may be formed by using one or more character operands together with character operators and parentheses.

____________________________ | | | | Operator | Representing | |__________|_______________| | | | | // | Concatenation | |__________|_______________|

The interpretation of the expression formed with the character operator is:

____________________________________________ | | | | Use of Operator | Interpretation | |_________________|________________________| | | | | x // x | Concatenate x with x | | 1 2 | 1 2 | |_________________|________________________|where:

- x
_{1}denotes the operand to the left of the operator - x
_{2}denotes the operand to the right of the operator

The result of a concatenation operation is a character string whose value is the value of x_{1} concatenated on the right with the value of x_{2} and whose length is the sum of the lengths of x_{1} and x_{2}. For example, the value of 'AB' // 'CDE' is the string ABCDE.

- Character constant (4.8.1)
- Symbolic name of a character constant (8.6)
- Character variable reference (2.5)
- Character array element reference (5.3)
- Character substring reference (5.7)
- Character function reference (15.2)
- Character expression enclosed in parentheses (6.2.2.2)

- Character primary
- Character expression // character primary

Thus, a character expression is a sequence of one or more character primaries separated by the concatenation operator. Form (2) indicates that in a character expression containing two or more concatenation operators, the primaries are combined from left to right to establish the interpretation of the expression. For example, the formation rules specify that the interpretation of the character expression

'AB' // 'CD' // 'EF'

is the same as the interpretation of the character expression

('AB' // 'CD') // 'EF'

The value of the character expression in this example is the same as that of the constant 'ABCDEF'. Note that parentheses have no effect on the value of a character expression.

Relational expressions may appear only within logical expressions. Evaluation of a relational expression produces a result of type logical, with a value of true or false.

_______________________________________ | | | | Operator | Representing | |__________|__________________________| | | | | .LT. | Less than | | .LE. | Less than or equal to | | .EQ. | Equal to | | .NE. | Not equal to | | .GT. | Greater than | | .GE. | Greater than or equal to | |__________|__________________________|

e_{1}relope_{2}

where:

*e*_{1}and*e*_{2}are each an integer, real, double precision, or complex expression*relop*is a relational operator

A complex operand is permitted only when the relational operator is .EQ. or .NE.

If the two arithmetic expressions are of different types, the value of the relational expression

e_{1}relope_{2}

is the value of the expression

((e_{1}) - (e_{2}))relop0

where 0 (zero) is of the same type as the expression ((*e*_{1}) (*e* ))_{2}, and *relop* is the same relational operator in both expressions. Note that the comparison of a double precision value and a complex value is not permitted.

e_{1}relope_{2}

where:

*e*_{1}and*e*_{2}are character expressions*relop*is a relational operator

The character expression *e*_{1} is considered to be less than *e*_{2} if the value of *e*_{1} precedes the value of *e*_{2} in the collating sequence; *e*_{1} is greater than *e*_{2} if the value of *e*_{1} follows the value of *e*_{2} in the collating sequence (3.1.5). Note that the collating sequence depends partially on the processor; however, the result of the use of the operators .EQ. and .NE. does not depend on the collating sequence. If the operands are of unequal length, the shorter operand is considered as if it were extended on the right with blanks to the length of the longer operand.

The simplest form of a logical expression is a logical constant, symbolic name of a logical constant, logical variable reference, logical array element reference, logical function reference, or relational expression. More complicated logical expressions may be formed by using one or more logical operands together with logical operators and parentheses.

____________________________________________ | | | | Operator | Representing | |__________|_______________________________| | | | | .NOT. | Logical Negation | | .AND. | Logical Conjunction | | .OR. | Logical Inclusive Disjunction | | .EQV. | Logical Equivalence | | .NEQV. | Logical Nonequivalence | |__________|_______________________________|

________________________________ | | | | Operator | Precedence | |_________________|____________| | | | | .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)

The *logical operands* are:

- Logical primary
- Logical factor
- Logical term
- Logical disjunct
- Logical expression

The formation rules to be applied in establishing the interpretation of a logical expression are in 6.4.2.1 through 6.4.2.5.

- Logical constant (4.7.1)
- Symbolic name of a logical constant (8.6)
- Logical variable reference (2.5)
- Logical array element reference (5.3)
- Logical function reference (15.2)
- Relational expression (6.3)
- Logical expression enclosed in parentheses (6.4.2.5)

- Logical primary
- logical primary

- Logical factor
- Logical term .AND. logical factor

Thus, a logical term is a sequence of logical factors separated by the .AND. operator. Form (2) indicates that in interpreting a logical term containing two or more .AND. operators, the logical factors are combined from left to right.

- Logical term
- Logical disjunct .OR. logical term

Thus, a logical disjunct is a sequence of logical terms separated by the .OR. operator. Form (2) indicates that in interpreting a logical disjunct containing two or more .OR. operators, the logical terms are combined from left to right.

- Logical disjunct
- Logical expression .EQV. logical disjunct
- Logical expression .NEQV. logical disjunct

Thus, a logical expression is a sequence of logical disjuncts separated by either the .EQV. operator or the .NEQV. operator. Forms (2) and (3) indicate that in interpreting a logical expression containing two or more .EQV. or .NEQV. operators, the logical disjuncts are combined from left to right.

____________________ | | | | x | .NOT. x | | 2 | 2 | |_______|__________| | | | | true | false | | false | true | |_______|__________|

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

_______________________________ | | | | | x | x | x .AND. x | | 1 | 2 | 1 2 | |_______|_______|_____________| | | | | | true | true | true | | true | false | false | | false | true | false | | false | false | false | |_______|_______|_____________|

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

______________________________ | | | | | x | x | x .OR. x | | 1 | 2 | 1 2 | |_______|_______|____________| | | | | | true | true | true | | true | false | true | | false | true | true | | false | false | false | |_______|_______|____________|

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

_______________________________ | | | | | x | x | x .EQV. x | | 1 | 2 | 1 2 | |_______|_______|_____________| | | | | | true | true | true | | true | false | false | | false | true | false | | false | false | true | |_______|_______|_____________|

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

________________________________ | | | | | x | x | x .NEQV. x | | 1 | 2 | 1 2 | |_______|_______|______________| | | | | | true | true | false | | true | false | true | | false | true | true | | false | false | false | |_______|_______|______________|

___________________________ | | | | Operator | Precedence | |____________|____________| | | | | Arithmetic | Highest | | Character | | | Relational | | | Logical | Lowest | |____________|____________|

An expression may contain more than one kind of operator. For example, the logical expression

L .OR. A + B .GE. C

where A, B, and C are of type real, and L is of type logical, contains an arithmetic operator, a relational operator, and a logical operator. This expression would be interpreted the same as the expression

L .OR. ((A + B) .GE. C)

- Use of parentheses
- Precedence of the operators
- Right-to-left interpretation of exponentiations in a factor
- Left-to-right interpretation of multiplications and divisions in a term
- Left-to-right interpretation of additions and subtractions in an arithmetic expression
- Left-to-right interpretation of concatenations in a character expression
- Left-to-right interpretation of conjunctions in a logical term
- Left-to-right interpretation of disjunctions in a logical disjunct
- Left-to-right interpretation of logical equivalences in a logical expression

Any variable, array element, function, or character substring referenced as an operand in an expression must be defined at the time the reference is executed. An integer operand must be defined with an integer value rather than a statement label value. Note that if a character string or substring is referenced, all of the referenced characters must be defined at the time the reference is executed.

Any arithmetic operation whose result is not mathematically defined is prohibited in the execution of an executable program. Examples are dividing by zero and raising a zero- valued primary to a zero-valued or negative-valued power. Raising a negative-valued primary to a real or double precision power is also prohibited.

The execution of a function reference in a statement may not alter the value of any other entity within the statement in which the function reference appears. The execution of a function reference in a statement may not alter the value of any entity in common (8.3) that affects the value of any other function reference in that statement. However, execution of a function reference in the expression *e* of a logical IF statement (11.5) is permitted to affect entities in the statement *st* that is executed when the value of the expression *e* is true. If a function reference causes definition of an actual argument of the function, that argument or any associated entities must not appear elsewhere in the same statement. For example, the statements

A(I) = F(I) Y = G(X) + X

are prohibited if the reference to F defines I or the reference to G defines X.

The data type of an expression in which a function reference appears does not affect the evaluation of the actual arguments of the function. The data type of an expression in which a function reference appears is not affected by the evaluation of the actual arguments of the function, except that the result of a generic function reference assumes a data type that depends on the data type of its arguments as specified in 15.10.

Any execution of an array element reference requires the evaluation of its subscript. The data type of an expression in which a subscript appears does not affect, nor is it affected by, the evaluation of the subscript.

Any execution of a substring reference requires the evaluation of its substring expressions. The data type of an expression in which a substring name appears does not affect, nor is it affected by, the evaluation of the substring expressions.

X .GT. Y .OR. L(Z)

where X, Y, and Z are real, and L is a logical function, the function reference L(Z) need not be evaluated if X is greater than Y. If a statement contains a function reference in a part of an expression that need not be evaluated, all entities that would have become defined in the execution of that reference become undefined at the completion of evaluation of the expression containing the function reference. In the example above, evaluation of the expression causes Z to become undefined if L defines its argument.

Y = F(G(X))

where F and G are functions, requires G to be evaluated before F is evaluated.

In a statement that contains more than one function reference, the value provided by each function reference must be independent of the order chosen by the processor for evaluation of the function references.

Two arithmetic expressions are mathematically equivalent if, for all possible values of their primaries, their mathematical values are equal. However, mathematically equivalent arithmetic expressions may produce different computational results.

The mathematical definition of integer division is given in 6.1.5. The difference between the value of the expression 5/2 and 5./2. is a mathematical difference, not a computational difference.

The following are examples of expressions, along with allowable alternative forms that may be used by the processor in the evaluation of those expressions. A, B, and C represent arbitrary real, double precision, or complex operands; I and J represent arbitrary integer operands; and X, Y, and Z represent arbitrary arithmetic operands. (Note that Table 2 prohibits combinations of double precision and complex data types.)

___________________________________________ | | | | Expression | Allowable Alternative Form | |____________|____________________________| | | | | X+Y | Y+X | | X*Y | Y*X | | -X+Y | Y-X | | X+Y+Z | X+(Y+Z) | | X-Y+Z | X-(Y-Z) | | X*B/Z | X*(B/Z) | | X*Y-X*Z | X*(Y-Z) | | A/B/C | A/(B*C) | | A/5.0 | 0.2*A | |____________|____________________________|

The following are examples of expressions along with forbidden forms that must not be used by the processor in the evaluation of those expressions.

__________________________________________ | | | | Expression | Nonallowable Alternative | | | Form | |_____________|__________________________| | | | | I/2 | 0.5*I | | X*I/J | X*(I/J) | | I/J/A | I/(J*A) | | (X*Y)-(X*Z) | X*(Y-Z) | | X*(Y-Z) | X*Y-X*Z | |_____________|__________________________|

In addition to the parentheses required to establish the desired interpretation, parentheses may be included to restrict the alternative forms that may be used by the processor in the actual evaluation of the expression. This is useful for controlling the magnitude and accuracy of intermediate values developed during the evaluation of an expression. For example, in the expression

A+(B-C)

the term (B-C) must be evaluated and then added to A. Note that the inclusion of parentheses may change the mathematical value of an expression. For example, the two expressions:

A*I/J A*(I/J)

may have different mathematical values if I and J are factors of integer data type.

Each operand of an arithmetic operator has a data type that may depend on the order of evaluation used by the processor. For example, in the evaluation of the expression

D+R+I

where D, R, and I represent terms of double precision, real, and integer data type, respectively, the data type of the operand that is added to I may be either double precision or real, depending on which pair of operands (D and R, R and I, or D and I) is added first.

CHARACTER*2 C1,C2,C3,CF C1 = C2 // CF(C3)

do not require the function CF to be evaluated, because only the value of C2 is needed to determine the value of C1.

I .GT. J

where I and J are integer variables, as

J - I .LT. 0

Two relational expressions are relationally equivalent if their logical values are equal for all possible values of their primaries.

L1 .AND. L2 .AND. L3

where L1, L2, and L3 are logical variables, as

L1 .AND. (L2 .AND. L3)

Two logical expressions are logically equivalent if their values are equal for all possible values of their primaries.