Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

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.

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.

Examples

Valid Numeric Assignment Statements

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 Numeric Assignment Statements

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.