See COMPLEX and DOUBLE COMPLEX (IBM extension) for details on declaring entities of type complex.
The following table shows the corresponding values for the kind type parameter and the length specification when the complex type specifier has the COMPLEX keyword:
Kind Type Parameter i |
Length Specification j |
---|---|
4 |
8 |
In XL Fortran, the kind type parameter specifies the precision of each part of the complex entity, while the length specification specifies the length of the whole complex entity.
The kind of a complex constant is determined by the kind of the constants in the real and imaginary parts.
The precision of DOUBLE COMPLEX values is twice that of default complex values.
Scalar values of type complex can be formed using complex constructors. The form of a complex constructor is:
A complex literal constant is a complex constructor where each expression is a pair of constant expressions. Variables and expressions can be used in each part of the complex constructor as an XL Fortran extension.
In Fortran 95 you are only allowed to use a single signed integer, or real literal constant in each part of the complex constructor. In Fortran 2003, you can also use a named constant.
Complex part designators follow the rules for real data types. In addition, you can use complex part designators as variables in assignment statements; if x is of type complex, x%IM=0.0 sets the imaginary part of x to zero.
If both parts of the literal constant are of type real, the kind type parameter of the literal constant is the kind parameter of the part with the greater precision, and the kind type parameter of the part with lower precision is converted to that of the other part.
If both parts are of type integer, they are each converted to type default real. If one part is of type integer and the other is of type real, the integer is converted to type real with the precision of the real part.
See COMPLEX and DOUBLE COMPLEX (IBM extension) for details on declaring entities of type complex.
Each part of a complex number has the same internal representation as a real number with the same kind type parameter.
(3_2,-1.86) ! Integer constant 3 is converted to default real
! for constant 3.0.
(45Q6,6D45) ! The imaginary part is converted to extended
! precision 6.Q45.
(1+1,2+2) ! Use of constant expressions. Both parts are
! converted to default real.
COMPLEX :: x, y, z
print *, x%RE ! Prints the same value as REAL(x)
print *, y%IM ! Prints the same value as AIMAG(y)
z%IM = 0.0 ! Sets the imaginary part of z to zero