# Complex Data Types

Complex data types can be specified as follows:

COMPLEX

COMPLEX([KIND=]n)

COMPLEX*s

DOUBLE COMPLEX

n | Is a constant expression that evaluates to kind 4, 8, or 16.
s | Is 8, 16, or 32. COMPLEX(4) is specified as COMPLEX*8; COMPLEX(8) is specified as COMPLEX*16; COMPLEX(16) is specified as COMPLEX*32.

If a kind parameter is specified, the complex constant has the kind specified. If no kind parameter is specified, the kind of both parts is default real, and the constant is of type default complex.

Default real is affected by compiler option real-size and by the REAL directive.

The default KIND for DOUBLE COMPLEX is affected by compiler option double-size. If the compiler option is not specified, default DOUBLE COMPLEX is COMPLEX(8).

No kind parameter is permitted for data declared with type DOUBLE COMPLEX.

A complex number of any kind is made up of a real part and an imaginary part. The REAL and AIMAG intrinsic functions return the real and imaginary parts of a complex number respectively. The CMPLX intrinsic constructs a complex number from two real numbers. The %re and %im complex part designators access the real and imaginary parts of a complex number respectively.

## Examples

The following examples show how complex variables can be declared.

An entity-oriented example is:

     COMPLEX (4), DIMENSION (8) :: cz, cq

An attribute-oriented example is:

     COMPLEX(4) cz, cq
     DIMENSION(8) cz, cq

The following shows an example of the parts of a complex number:

     COMPLEX (4) :: ca = (1.0, 2.0)
     REAL (4) :: ra = 3.0, rb = 4.0
     PRINT *, REAL (ca), ca%RE            ! prints 1.0, 1.0
     PRINT *, AIMAG (ca), ca%IM           ! prints 2.0, 2.0
     PRINT *, CMPLX (ra, rb)              ! prints (3.0, 4.0)
     ca = CMPLX (ra, AIMAG (ca))
     PRINT *, ca                          ! prints (3.0, 2.0)
     ca%im = rb
     PRINT *, ca                          ! prints (3.0, 4.0)

## See Also

General Rules for Complex Constants
AIMAG intrinsic
CMPLX intrinsic
COMPLEX(4) Constants
COMPLEX(8) or DOUBLE COMPLEX Constants
REAL intrinsic