LF Fortran 95

CMPLX Function


The CMPLX function uses REAL or INTEGER arguments to compose a result of type COMPLEX. It may also convert between different kinds of COMPLEX numbers, possibly resulting in a loss of precision.


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

Required Arguments

x is an INTENT(IN) scalar or array of type REAL, INTEGER, or COMPLEX.

Optional Arguments

y is INTENT(IN) and of type REAL or INTEGER. If x is of type COMPLEX, y cannot be present.

kind is a number which determines the kind of the result. It must be a scalar INTEGER expression that can be evaluated at compile time. To maintain portability, this argument should be the result of a KIND Function, or SELECTED_REAL_KIND Function.


The result is of type COMPLEX.

If x is INTEGER or REAL, the value of the result is the complex number whose real part has the value of x, and whose imaginary part has the value of y. If y is absent, the imaginary part of the result is zero.

If x is COMPLEX, it is as if x and y were present with the values REAL(x), AIMAG(x)).

If kind is present, the result is of the kind specified by kind.

If kind is absent, the result is default kind.


real :: x=1.,y=1. integer :: ix=1,iy=1 complex(kind(1.d0)) :: z=(1.d0,1.d0) write(*,*) cmplx(x) ! y assumed to be zero write(*,*) cmplx(x,y) write(*,*) cmplx(ix,iy,kind(1.d0)) write(*,*) cmplx(ix,y) write(*,*) z, cmplx(z) ! precision is lost

See Also

KIND Function