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:
___________________________________________________ | | | |_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 ** 2the 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:
The formation rules to be applied in establishing the interpretation of arithmetic expressions are in 188.8.131.52 through 184.108.40.206.
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**2has the same interpretation as the 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.
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:
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.
____________________________________________________________ | | | | | 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.
____________________________________________________________ | | | | | 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.
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|
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.
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 relop e 1 2
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 relop e 1 2is the value of the expression
((e ) - (e )) relop 0 1 2where 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.
e relop e 1 2
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. Cthe .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:
The formation rules to be applied in establishing the interpretation of a logical expression are in 220.127.116.11 through 18.104.22.168.
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.
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.
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.
__________________ | | | |__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 | |______|_______|______________|
_________________________ | | | |_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. Cwhere 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)
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) + Xare 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)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+Iwhere 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.
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. Jwhere I and J are integer variables, as
J - I .LT. 0Two relational expressions are relationally equivalent if their logical values are equal for all possible values of their primaries.
L1 .AND. L2 .AND. L3where 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.