Intel® Fortran Compiler 16.0 User and Reference Guide
If every operand in a numeric expression is of the same data type, the result is also of that type.
If operands of different data types are combined in an expression, the evaluation of that expression and the data type of the resulting value depend on the ranking associated with each data type. The following table shows the ranking assigned to each data type:
Data Type |
Ranking |
---|---|
LOGICAL(1) and BYTE |
Lowest |
LOGICAL(2) |
. |
LOGICAL(4) |
. |
LOGICAL(8) |
. |
INTEGER(1) |
. |
INTEGER(2) |
. |
INTEGER(4) |
. |
INTEGER(8) |
. |
REAL(4) |
. |
REAL(8)1 |
. |
REAL(16) |
. |
COMPLEX(4) |
. |
COMPLEX(8)2 |
. |
COMPLEX(16) |
Highest |
The data type of the value produced by an operation on two numeric operands of different data types is the data type of the highest-ranking operand in the operation. For example, the value resulting from an operation on an integer and a real operand is of real type. However, an operation involving a COMPLEX(4) or COMPLEX(8) data type and a DOUBLE PRECISION data type produces a COMPLEX(8) result.
The data type of an expression is the data type of the result of the last operation in that expression, and is determined according to the following conventions:
Integer operations: Integer operations are performed only on integer operands. (Logical entities used in a numeric context are treated as integers.) In integer arithmetic, any fraction resulting from division is truncated, not rounded. For example, the result of 9/10 is 0, not 1.
Real operations: Real operations are performed only on real operands or combinations of real, integer, and logical operands. Any integer operands present are converted to real data type by giving each a fractional part equal to zero. The expression is then evaluated using real arithmetic. However, in the statement Y = (I /J)*X, an integer division operation is performed on I and J, and a real multiplication is performed on that result and X.
If one operand is a higher-precision real (REAL(8) or REAL(16)) type, the other operand is converted to that higher-precision real type before the expression is evaluated.
When a single-precision real operand is converted to a double-precision real operand, low-order binary digits are set to zero. This conversion does not increase accuracy; conversion of a decimal number does not produce a succession of decimal zeros. For example, a REAL variable having the value 0.3333333 is converted to approximately 0.3333333134651184D0. It is not converted to either 0.3333333000000000D0 or 0.3333333333333333D0.
Complex operations: In operations that contain any complex operands, integer operands are converted to real type, as previously described. The resulting single-precision or double-precision operand is designated as the real part of a complex number and the imaginary part is assigned a value of zero. The expression is then evaluated using complex arithmetic and the resulting value is of complex type. Operations involving a COMPLEX(4) or COMPLEX(8) operand and a DOUBLE PRECISION operand are performed as COMPLEX(8) operations; the DOUBLE PRECISION operand is not rounded.
These rules also generally apply to numeric operations in which one of the operands is a constant. However, if a real or complex constant is used in a higher-precision expression, additional precision will be retained for the constant. The effect is as if a DOUBLE PRECISION (REAL(8)) or REAL(16) representation of the constant were given. For example, the expression 1.0D0 + 0.3333333 is treated as if it is 1.0D0 + dble(0.3333333).