An arithmetic expression specifies a numeric computation that yields a numeric value on evaluation. The simplest form of an arithmetic expression can be:
You can form more complicated arithmetic expressions from one or more operands together with arithmetic operators and parentheses.
An arithmetic element can include logical entities because logical data is treated as integer data when used in an arithmetic context. When both arithmetic and logical operands exist for a given operator, the logical operand is promoted to type INTEGER of the same byte length as the original logical length. For example, a LOGICAL*2 will be promoted to INTEGER*2 and a LOGICAL*4 will be promoted to INTEGER*4.
Table below shows the arithmetic operators.
Table: Arithmetic Operators
Use the exponentiation, division, and multiplication operators between exactly two operands. You can use the addition and subtraction operators with one or two operands; in the latter case, specify the operator before the operand; for example, –TOTAL.
Do not specify two operators in succession. (Note that the exponentiation operator consists of the two characters (**), but is a single operator.) Implied operators, as in implied multiplication, are not allowed.
Interpretation of Arithmetic Expressions
Table below showsinterprets sample arithmetic expressions.
Table : Interpretation of Arithmetic Expressions
An arithmetic expression containing two or more operators is interpreted based on a precedence relation among the arithmetic operators. This precedence, from highest to lowest, is
Use parentheses to override the order of precedence.
The following is an example of an arithmetic expression:
The operators are executed in the following sequence:
A unary operator (–) can follow another operator. Specifying the unary operator after the exponentiation operator produces a variation on the standard order of operations. The unary operator is evaluated first in that case, resulting in exponentiation taking a lower precedence in the expression.
For example, the following expressionA ** - B * C
Arithmetic operands must specify values with integer, real, double-precision, complex, or double-complex data types. You can combine specific operands in an arithmetic expression. The arithmetic operands, in order of increasing complexity, are
A primary is the basic component in an arithmetic expression. The forms of a primary are
A factor consists of one or more primaries separated by the exponentiation operator. The forms of a factor are
Factors with more than one exponentiation operator are interpreted from right to left. For example, I**J**K is interpreted as I**(J**K), and I**J**K**L is interpreted as I**(J**(K**L)).
The term incorporates the multiplicative operators into arithmetic expressions. Its forms are
The above definition indicates that factors are combined from left to right in a term containing two or more multiplication or division operators.
Finally, at the highest level of the hierarchy, are the arithmetic expressions. The forms of an arithmetic expression are
An arithmetic expression consists of one or more terms separated by an addition operator or a subtraction operator. The terms are combined from left to right. For example, A+B-C has the same interpretation as the expression (A+B)-C. Expressions such as A*-B and A+-B are not allowed. The correct forms are A*(-B) and A+(-B).
An arithmetic expression can begin with a plus or minus sign.
Arithmetic Constant Expressions
An arithmetic constant expression is an arithmetic expression containing no variables. Therefore, each primary in an arithmetic constant expression must be one of the following:
In an arithmetic constant expression, do not specify the exponentiation operator unless the exponent is of type integer. Variable, array element, and function references are not allowed. Examples of integer constant expressions are
x+3 (where x is the symbolic name of a constant)
Integer Constant Expressions
An integer constant expression is an arithmetic constant expression containing only integers. It can contain constants or symbolic names of constants, provided they are of type integer. As with all constant expressions, no variables, array elements, or function references are allowed.
Evaluating Arithmetic Expressions
The data type of an expression is determined by the data types of the operands and functions that are referenced. Thus, integer expressions, real expressions, double-precision expressions, complex expressions, and double expressions have values of type integer, real, double-precision, complex, and double-complex, respectively.
Single-mode expressions are arithmetic expressions in which all operands have the same data type. The data type of the value of a single-mode expression is thus the same as the data type of the operands. When the addition operator or the subtraction operator is used with a single operand, the data type of the resulting expression is the same as the data type of the operand.
Mixed-mode expressions contain operands with two or more data types.
The data type of the result of a mixed-mode expression depends on the rank associated with each data type, as shown in Table below.
Table: Data Type Ranks
Except for exponentiation (discussed below), the result of a mixed-mode expression is assigned the data type of the highest-ranked element in the expression. The lower-ranked operand is converted to the type of the higher-ranked operand so that the operation is performed on values with equivalent data types. For example, an operation on an integer operand and a real operand produces a result of type real.
Operations that combine REAL*8 (DOUBLE PRECISION) and COMPLEX*8 (COMPLEX) are not allowed. The REAL*8 operand must be explicitly converted (for example, by using the SNGL intrinsic function).
Exponentiation is an exception to the above rules for mixed-mode expressions. When raising a value to an integer power, the integer is not converted. The result is assigned the type of the left operand.
When a complex value is raised to a complex power, the value of the
expression is defined as follows:
xy = EXP (y * LOG(x))
One operand of type integer can be divided by another operand of type integer. The result of an integer division operation is a value of type integer, referred to as an integer quotient. The integer quotient is obtained as follows:
Fortran Elements And Concepts
Constants And Data Structures
Assignment And Data Statements
Statement Functions And Subprograms
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.