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

ID 767251
Date 6/24/2024
Public

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

Document Table of Contents

CMPLX

Elemental Intrinsic Function (Specific): Converts the argument to complex type. This function cannot be passed as an actual argument.

This intrinsic function can take one of the following forms:

result = CMPLX (x [,kind])

x

(Input) Must be of type complex.

kind

(Input; optional) Must be a scalar integer constant expression.

or

result = CMPLX (x [,y ,kind])

x

(Input) Must be of type integer, real, or a binary, octal, or hexadecimal literal constant.

y

(Input; optional) Must be of type integer, real, or a binary, octal, or hexadecimal literal constant.

kind

(Input; optional) Must be a scalar integer constant expression.

Results

The result type is complex. If kind is present, the kind parameter is that specified by kind; otherwise, the kind parameter is that of default real type.

If x is type complex, y must not be specified, and the result value is CMPLX (REAL (x), AIMAG (x)), with default kind if kind is not present, otherwise with the kind type as specified by kind.

If x is present and not of complex type, and y is not present, x is converted into the real part of the result value and zero is assigned to the imaginary part.

If x and y are present, the complex value is produced by converting the x into the real part of the value, and converting the y into the imaginary part.

CMPLX (x, y, kind) has the complex value whose real part is REAL (x, kind) and whose imaginary part is REAL (y, kind).

The setting of compiler options specifying real size can affect this function.

If the argument is a binary, octal, or hexadecimal literal constant, the result is affected by the assume old-boz option. The default option setting, noold-boz, treats the argument as a bit string that represents a value of the data type of the intrinsic, that is, the bits are not converted. If setting old-boz is specified, the argument is treated as a signed integer and the bits are converted.

NOTE:

The result values of CMPLX are defined by references to the intrinsic function REAL with the same arguments. Therefore, the padding and truncation of binary, octal, and hexadecimal literal constant arguments to CMPLX is the same as for the intrinsic function REAL.

Example

CMPLX (-3) has the value (-3.0, 0.0).

CMPLX (4.1, 2.3) has the value (4.1, 2.3).

The following shows another example:

COMPLEX z1, z2
COMPLEX(8) z3
z1 = CMPLX(3)     ! returns the value 3.0 + i 0.0
z2 = CMPLX(3,4)   ! returns the value 3.0 + i 4.0
z3 = CMPLX(3,4,8) ! returns a COMPLEX(8) value 3.0D0 + i 4.0D0