6 EXPRESSIONS

This section describes the formation, interpretation, and evaluation rules for arithmetic, character, relational, and logical expressions. An expression is formed from operands, operators, and parentheses.

6.1 Arithmetic Expressions

An arithmetic expression is used to express a numeric computation. Evaluation of an arithmetic expression produces a numeric !value.

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.

6.1.1 Arithmetic Operators.

The five arithmetic operators are:
____________________________________
           |         |                         |
           |_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:

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

6.1.2 Form and Interpretation of Arithmetic Expressions.

The interpretation of the expression formed with each of the arithmetic operators in each form of use is as follows:
___________________________________________________
   |                |                                 |
   |_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_____________________|

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:
  1. Primary
  2. Factor
  3. Term
  4. 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.

6.1.2.1 Primaries.

The primaries are:
  1. Unsigned arithmetic constant ( 4.2.3)
  2. Symbolic name of an arithmetic constant ( 8.6)
  3. Arithmetic variable reference ( 2.5)
  4. Arithmetic array element reference ( 5.3)
  5. Arithmetic function reference ( 15.2)
  6. Arithmetic expression enclosed in parentheses ( 6.1.2.4)

6.1.2.2 Factor.

The forms of a factor are:
  1. Primary
  2. 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)

6.1.2.3 Term.

The forms of a term are:
  1. Factor
  2. Term / factor
  3. 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.

6.1.2.4 Arithmetic Expression.

The forms of an arithmetic expression are:
  1. Term
  2. + term
  3. - term
  4. Arithmetic expression + term
  5. 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.

6.1.3 Arithmetic Constant Expression.

An arithmetic constant expression is an arithmetic expression in which each primary is an arithmetic constant, the symbolic name of an arithmetic constant, or an arithmetic constant expression enclosed in parentheses. The exponentiation operator is not permitted unless the exponent is of type integer. Note that variable, array element, and function references are not allowed.

6.1.3.1 Integer Constant Expression.

An integer constant expression is an arithmetic constant expression in which each constant or symbolic name of a constant is of type integer. Note that variable, array element, and function references are not allowed.

The following are examples of integer constant expressions:

  1. 3
  2. -3
  3. -3+4

6.1.4 Type and Interpretation of Arithmetic Expressions.

The data type of a constant is determined by the form of the constant ( 4.2.1). The data type of an arithmetic variable reference, symbolic name of an arithmetic constant, arithmetic array element reference, or arithmetic function reference is determined by the name of the datum or function ( 4.1.2). The data type of an arithmetic expression containing one or more arithmetic operators is determined from the data types of the operands.

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.


Table_2

Type and Interpretation of Result for

x + x 1 2
____________________________________________________________
|      |                          |                        |
|  x2  |            I2            |           R2           |
|x1____|__________________________|________________________|
|      |                          |                        |
|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_____|
____________________________________________________________
|       |                      |                           |
|   x2  |          D2          |             C2            |
|_x1____|______________________|___________________________|
|       |                      |                           |
| 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.


Table_3

Type and Interpretation of Result for

x **x 1 2
____________________________________________________________
|          |                   |                           |
|    x2    |         I2        |              R2           |
|__x1______|___________________|___________________________|
|          |                   |                           |
|  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______|
____________________________________________________________
|       |                     |                            |
|   x2  |          D2         |              C2            |
|_x1____|_____________________|____________________________|
|       |                     |                            |
| 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 **x = EXP(x *LOG(x )) 1 2 2 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 **I 1 2 is the same as the interpretation of 1/(I **ABS(I )) 1 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.

6.1.5 Integer Division.

One operand of type integer may be divided by another operand of type integer. Although the mathematical quotient of two integers is not necessarily an integer, Table 2 specifies that an expression involving the division operator with two operands of type integer is interpreted as an expression of type integer. The result of such a division is called an integer quotient and is obtained as follows: If the magnitude of the mathematical quotient is less than one, the integer quotient is zero. Otherwise, the integer quotient is the integer whose magnitude is the largest integer that does not exceed the magnitude of the mathematical quotient and whose sign is the same as the sign of the mathematical quotient. For example, the value of the expression (-8)/3 is (-2).

6.2 Character Expressions

A character expression is used to express a character string. Evaluation of a character expression produces a result of type character.

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.

6.2.1 Character Operator.

The character operator is:
__________________________
                |         |               |
                |_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|

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.

6.2.2 Form and Interpretation of Character Expressions.

A character expression and the operands of a character expression must identify values of type character. Except in a character assignment statement ( 10.4), a character expression must not involve concatenation of an operand whose length specification is an asterisk in parentheses ( 8.4.2) unless the operand is the symbolic name of a constant.

6.2.2.1 Character Primaries.

The character primaries are:
  1. Character constant ( 4.8.1)
  2. Symbolic name of a character constant ( 8.6)
  3. Character variable reference ( 2.5)
  4. Character array element reference ( 5.3)
  5. Character substring reference ( 5.7)
  6. Character function reference ( 15.2)
  7. Character expression enclosed in parentheses ( 6.2.2.2)

6.2.2.2 Character Expression.

The forms of a character expression are:
  1. Character primary
  2. 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.

6.2.3 Character Constant Expression.

A character constant expression is a character expression in which each primary is a character constant, the symbolic name of a character constant, or a character constant expression enclosed in parentheses. Note that variable, array element, substring, and function references are not allowed.

6.3 Relational Expressions

A relational expression is used to compare the values of two arithmetic expressions or two character expressions. A relational expression may not be used to compare the value of an arithmetic expression with 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.

6.3.1 Relational Operators.

The relational operators are:
_____________________________________
          |         |                          |
          |_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|
          |_________|__________________________|

6.3.2 Arithmetic Relational Expression.

The form of an arithmetic relational expression is:
e  relop e
                         1        2

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

6.3.3 Interpretation of Arithmetic Relational Expressions.

An arithmetic relational expression is interpreted as having the logical value true if the values of the operands satisfy the relation specified by the operator. An arithmetic relational expression is interpreted as having the logical value false if the values of the operands do not satisfy the relation specified by the operator.

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

e  relop e
                         1        2
is the value of the expression
((e ) - (e )) relop 0
                      1      2
where 0 (zero) is of the same type as the expression ((e ) (e )) 1 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.

6.3.4 Character Relational Expression.

The form of a character relational expression is:
e  relop e
                         1        2

6.3.5 Interpretation of Character Relational Expressions.

A character relational expression is interpreted as the logical value true if the values of the operands satisfy the relation specified by the operator. A character relational expression is interpreted as the logical value false if the values of the operands do not satisfy the relation specified by the 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.

6.4 Logical Expressions

A logical expression is used to express a logical computation. Evaluation of a logical expression produces a result of type logical, with a value of true or false.

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.

6.4.1 Logical Operators.

The logical operators are:
__________________________________________
        |         |                               |
        |_Operator|__Representing_________________|
        |         |                               |
        |  .NOT.  |  Logical Negation             |
        |  .AND.  |  Logical Conjunction          |
        |   .OR.  |  Logical Inclusive Disjunction|
        |  .EQV.  |  Logical Equivalence          |
        |  .NEQV. |  Logical Nonequivalence       |
        |_________|_______________________________|

6.4.2 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:
______________________________
              |                |            |
              |____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:
  1. Logical primary
  2. Logical factor
  3. Logical term
  4. Logical disjunct
  5. 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.

6.4.2.1 Logical Primaries.

The logical primaries are:
  1. Logical constant ( 4.7.1)
  2. Symbolic name of a logical constant ( 8.6)
  3. Logical variable reference ( 2.5)
  4. Logical array element reference ( 5.3)
  5. Logical function reference ( 15.2)
  6. Relational expression ( 6.3)
  7. Logical expression enclosed in parentheses ( 6.4.2.5)

6.4.2.2 Logical Factor.

The forms of a logical factor are:
  1. Logical primary
  2. logical primary

6.4.2.3 Logical Term.

The forms of a logical term are:
  1. Logical factor
  2. 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.

6.4.2.4 Logical Disjunct.

The forms of a logical disjunct are:
  1. Logical term
  2. 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.

6.4.2.5 Logical Expression.

The forms of a logical expression are:
  1. Logical disjunct
  2. Logical expression .EQV. logical disjunct
  3. 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.

6.4.3 Value of Logical Factors, Terms, Disjuncts, and Expressions.

The value of a logical factor involving .NOT. is shown below:
__________________
                    |      |          |
                    |__x2__|__.NOT._x2|
                    |      |          |
                    | true |   false  |
                    | false|   true   |
                    |______|__________|

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

_____________________________
              |      |       |             |
              |__x1__|___x2__|__x1_.AND._x2|
              |      |       |             |
              | true |  true |     true    |
              | true |  false|     false   |
              | false|  true |     false   |
              | false|  false|     false   |
              |______|_______|_____________|

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

____________________________
               |      |       |            |
               |__x1__|___x2__|__x1_.OR._x2|
               |      |       |            |
               | true |  true |    true    |
               | true |  false|    true    |
               | false|  true |    true    |
               | false|  false|    false   |
               |______|_______|____________|

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

_____________________________
              |      |       |             |
              |__x1__|___x2__|__x1_.EQV._x2|
              |      |       |             |
              | true |  true |     true    |
              | true |  false|     false   |
              | false|  true |     false   |
              | false|  false|     true    |
              |______|_______|_____________|

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

______________________________
              |      |       |              |
              |__x1__|___x2__|__x1_.NEQV._x2|
              |      |       |              |
              | true |  true |     false    |
              | true |  false|     true     |
              | false|  true |     true     |
              | false|  false|     false    |
              |______|_______|______________|

6.4.4 Logical Constant Expression.

A logical constant expression is a logical expression in which each primary is a logical constant, the symbolic name of a logical constant, a relational expression in which each primary is a constant expression, or a logical constant expression enclosed in parentheses. Note that variable, array element, and function references are not allowed.

6.5 Precedence of Operators

In 6.1.2 and 6.4.2 precedences have been established among the arithmetic operators and the logical operators, respectively. There is only one character operator. No precedence has been established among the relational operators. The precedences among the various operators are:
_________________________
                |           |            |
                |_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)

6.5.1 Summary of Interpretation Rules.

The order in which primaries are combined using operators is determined by the following:
  1. Use of parentheses
  2. Precedence of the operators
  3. Right-to-left interpretation of exponentiations in a factor
  4. Left-to-right interpretation of multiplications and divisions in a term
  5. Left-to-right interpretation of additions and subtractions in an arithmetic expression
  6. Left-to-right interpretation of concatenations in a character expression
  7. Left-to-right interpretation of conjunctions in a logical term
  8. Left-to-right interpretation of disjunctions in a logical disjunct
  9. Left-to-right interpretation of logical equivalences in a logical expression

6.6 Evaluation of Expressions

This section applies to arithmetic, character, relational, and logical expressions.

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.

6.6.1 Evaluation of Operands.

It is not necessary for a processor to evaluate all of the operands of an expression if the value of the expression can be determined otherwise. This principle is most often applicable to logical express(ions, but it applies to all expressions. For example, in evaluating the logical expression
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.

6.6.2 Order of Evaluation of Functions.

If a statement contains more than one function reference, a processor may evaluate the functions in any order, except for a logical IF statement and a function argument list containing function references. For example, the statement
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.

6.6.3 Integrity of Parentheses.

The sections that follow state certain conditions under which a processor may evaluate an expression different from the one obtained by applying the interpretation rules given in 6.1 through 6.5. However, any expression contained in parentheses must be treated as an entity. For example, in evaluating the expression A*(B*C), the product of B and C must be evaluated and then multiplied by A; the processor must not evaluate the mathematically equivalent expression (A*B)*C.

6.6.4 Evaluation of Arithmetic Expressions.

The rules given in 6.1.2 specify the interpretation of an arithmetic expression. Once the interpretation has been established in accordance with those rules, the processor may evaluate any mathematically equivalent expression, provided that the integrity of parentheses is not violated.

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.

6.6.5 Evaluation of Character Expressions.

The rules given in 6.2.2 specify the interpretation of a character expression as a string of characters. A processor needs to evaluate only as much of the character expression as is required by the context in which the expression appears. For example, the statements
  1. CHARACTER*2 C1,C2,C3,CF
  2. 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.

6.6.6 Evaluation of Relational Expressions.

The rules given in 6.3.3 and 6.3.5 specify the interpretation of relational expressions. Once the interpretation of an expression has been established in accordance with those rules, the processor may evaluate any other expression that is relationally equivalent. For example, the processor may choose to evaluate the relational expression
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.

6.6.7 Evaluation of Logical Expressions.

The rules given in 6.4.2 specify the interpretation of a logical expression. Once the interpretation of an expression has been established in accordance with those rules, the processor may evaluate any other expression that is logically equivalent, provided that the integrity of parentheses is not violated. For example, the processor may choose to evaluate the logical expression
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.

6.7 Constant Expressions

A constant expression is an arithmetic constant expression ( 6.1.3), a character constant expression ( 6.2.3), or a logical constant expression ( 6.4.4).

'




[Contents] [Previous] [Next]
This document was translated by troff2html v0.21 on August 16, 1995.