### 4.2.1.1 Numeric Assignment Statements

For numeric assignment statements, the variable and expression must be numeric type.

The expression must yield a value that conforms to the range requirements of the variable. For example, a real expression that produces a value greater than 32767 is invalid if the entity on the left of the equal sign is an INTEGER(2) variable.

Significance can be lost if an INTEGER(4) value, which can exactly represent values of approximately the range -2*10**9 to +2*10**9, is converted to REAL(4) (including the real part of a complex constant), which is accurate to only about seven digits.

If the variable has the same data type as that of the expression on the right, the statement assigns the value directly. If the data types are different, the value of the expression is converted to the data type of the variable before it is assigned.

Table 4-2 summarizes the data conversion rules for numeric assignment statements.

REAL(16) and COMPLEX(16) are only available on OpenVMS, Tru64 UNIX, and Linux systems.

Table 4-2 Conversion Rules for Numeric Assignment Statements

Scalar Memory Reference (V) | Expression (E)
--- | ---
Integer, Logical or Real | Complex
Integer or Logical | V=INT(E) | V=INT(REAL(E)) Imaginary part of E is not used.
REAL (KIND=4) | V=REAL(E) | V=REAL(REAL(E)) Imaginary part of E is not used.
REAL (KIND=8) | V=DBLE(E) | V=DBLE(REAL(E)) Imaginary part of E is not used.
REAL (KIND=16) | V=QEXT(E) | V=QEXT(REAL(E)) Imaginary part of E is not used.
COMPLEX (KIND=4) | V=CMPLX(REAL(E), 0.0) | V=CMPLX(REAL(REAL(E)), REAL(AIMAG(E)))
COMPLEX (KIND=8) | V=CMPLX(DBLE(E), 0.0) | V=CMPLX(DBLE(REAL(E)), DBLE(AIMAG(E)))
COMPLEX (KIND=16) | V=CMPLX(QEXT(E), 0.0) | V=CMPLX(QEXT(REAL(E)), QEXT(AIMAG(E)))

For more information, see INT, REAL, DBLE, QEXT, CMPLX, and AIMAG.

Examples

The following examples demonstrate valid and invalid numeric assignment statements:

Valid |
`BETA = -1./(2.*X)+A*A /(4.*(X*X))`
`PI = 3.14159` |
`SUM = SUM + 1.` |
`ARRAY_A = ARRAY_B + ARRAY_C + SCALAR_I` | ! Valid if all arrays conform in shape
Invalid | Explanation
`3.14 = A - B` | Entity on the left must be a variable.
`ICOUNT = A//B(3:7)` | Implicitly typed data types do not match.
`SCALAR_I = ARRAY_A(:)` | Shapes do not match.

Previous Page Next Page Table of Contents