Node: CMPLX() of DOUBLE PRECISION, Next: MIL-STD 1753, Previous: REAL() and AIMAG() of Complex, Up: Functions and Subroutines

`CMPLX()`

of `DOUBLE PRECISION`

In accordance with Fortran 90 and at least some (perhaps all)
other compilers, the GNU Fortran language defines `CMPLX()`

as always returning a result that is type `COMPLEX(KIND=1)`

.

This means `CMPLX(D1,D2)`

, where `D1`

and `D2`

are `REAL(KIND=2)`

(`DOUBLE PRECISION`

), is treated as:

CMPLX(SNGL(D1), SNGL(D2))

(It was necessary for Fortran 90 to specify this behavior
for `DOUBLE PRECISION`

arguments, since that is
the behavior mandated by FORTRAN 77.)

The GNU Fortran language also provides the `DCMPLX()`

intrinsic,
which is provided by some FORTRAN 77 compilers to construct
a `DOUBLE COMPLEX`

entity from of `DOUBLE PRECISION`

operands.
However, this solution does not scale well when more `COMPLEX`

types
(having various precisions and ranges) are offered by Fortran implementations.

Fortran 90 extends the `CMPLX()`

intrinsic by adding
an extra argument used to specify the desired kind of complex
result.
However, this solution is somewhat awkward to use, and
`g77`

currently does not support it.

The GNU Fortran language provides a simple way to build a complex value out of two numbers, with the precise type of the value determined by the types of the two numbers (via the usual type-promotion mechanism):

COMPLEX(real,imag)

When `real` and `imag` are the same `REAL`

types, `COMPLEX()`

performs no conversion other than to put them together to form a
complex result of the same (complex version of real) type.

See Complex Intrinsic, for more information.