If every element in an arithmetic expression is of the same data
type, the value produced by the expression is also of that data
type. If elements 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; the lowest ranking is 1:
Data Type |
VAX Ranking | Alpha
Ranking |
BYTE |
1 | 1 |
LOGICAL*1 |
1 | 1 |
LOGICAL*2 |
2 | 2 |
LOGICAL
(LOGICAL*4) |
3 | 3 |
LOGICAL*8[1] |
None | 4 |
INTEGER*1 |
1 | 5 |
INTEGER*2 |
4 | 6 |
INTEGER
(INTEGER*4) |
5 | 7 |
INTEGER*8[1] |
None | 8 |
REAL (REAL*4) |
6 | 9 |
DOUBLE
PRECISION (REAL*8) |
7 | 10 |
REAL*16 |
8 | 11 |
COMPLEX
(COMPLEX*8) | 9 |
12 |
DOUBLE COMPLEX
(COMPLEX*16) | 10 | 13 |
[1] Alpha only
|
The data type of the value produced by an operation on two
arithmetic elements of different data types is the data type of
the highest-ranking element in the operation. For example, the data
type of the value resulting from an operation on an integer and a
real element is real. However, an operation
involving a COMPLEX data type and either a DOUBLE PRECISION or
REAL*16 data type produces a DOUBLE COMPLEX
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 elements. (Logical entities used
in an arithmetic context are treated as integers.) In
integer arithmetic, any fraction that can result from division is
truncated, not rounded. For example, the result of
1/4 + 1/4 + 1/4 +
1/4
is 0, not 1.
- Real operations: Real operations are performed
only on real elements or combinations of real, integer,
and logical elements. Any integer
elements present are converted to the real data type by giving
each a fractional part equal to zero. The expression is then
evaluated by 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.
- DOUBLE PRECISION (REAL*8) and REAL*16
operations: Any element in an operation
in which there is a higher-precision element is converted to the
data type of the higher-precision element by making the existing
element the most significant portion of the higher-precision
data. The least significant portion of the binary representation
is zero. The expression is then evaluated in the higher-precision
arithmetic.
- 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 elements, integer elements are converted to the real
data type, as previously described. The obtained REAL or DOUBLE
PRECISION element is then designated as the real part of a
complex number and the imaginary part is assigned a value
of zero. Next, the expression is evaluated by using complex
arithmetic and the resulting value is a complex data type.
Operations involving COMPLEX and DOUBLE
PRECISION elements are performed as DOUBLE COMPLEX operations;
the DOUBLE PRECISION element is not rounded.
- Constants defined by PARAMETER
statements: Constants in the range -128 to 127 can also be
treated as lower-order types in operations with BYTE quantities.
For example, if BYTE variable B is combined in an expression,
such as B+4, the integer constant is treated as a byte. So, the
expression ranking is 1, which eliminates the need to convert B
to INTEGER*2 before performing the addition. (This treatment can
result in integer overflow exceptions.)
These rules also generally apply to arithmetic 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
is given. For example, the expression 1.0D0 +
0.3333333
is treated as if it is 1.0D0 +
0.3333333000000000D0
.
Previous Page Next Page Table of Contents