Visible to Intel only — GUID: GUID-6D3F0FB9-9210-4AB1-BF6E-0342BC61EDA3
Visible to Intel only — GUID: GUID-6D3F0FB9-9210-4AB1-BF6E-0342BC61EDA3
Numeric Assignment Statements
For numeric assignment statements, the variable and expression must be numeric type. The expression may also be of logical 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.
The following table summarizes the data conversion rules for numeric assignment statements.
Scalar Memory Reference (V) |
Expression (E) |
|
---|---|---|
Integer or Real |
Complex |
|
Integer |
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))) |
If the expression (E) is of type logical, it is first converted to type integer as follows:
- If E evaluates to .TRUE. the result is -1 or 1 depending on the setting of the compiler option fpscomp logicals
- Otherwise the result is 0
The result of this conversion is then interpreted according to the above table.
If the variable is an enum type, the expression must be an enum type or integer. If the variable is of enum type type-name, and the expression is of integer type, the behavior is as if the statement was written as:
variable = type-name (expression)
where type-name (expression) is an enum constructor.
Examples
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 |
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. |