next up previous contents
Next: Parameterised Intrinsic Types Up: Fortran 90 Previous: USE ONLY Statement

 

Complex Data Type

 

This intrinsic data type has the same precision as default REAL and has comparable properties to other intrinsic data types.

A COMPLEX object is made up from two default REAL cells and is declared as follows:

    COMPLEX :: z, j, za(1:100)

Symbolic constants are expressed as a co-ordinate pair:

    COMPLEX, PARAMETER :: i = (0.0,1.0)
Real-valued literals and symbolic constants, and complex valued literals and symbolic constants can all be used in a COMPLEX object initialisation statement (for example, PARAMETER statement), but it is not permissible to allow a constructed value containing real-valued symbolic constants as components. So,
    INTEGER, PARAMETER :: a1 = 1, a2 = 2
    COMPLEX, PARAMETER :: i = (1.0,2.0)
    COMPLEX, PARAMETER :: ii = i
    COMPLEX, PARAMETER :: iii = a1
is OK, but

    COMPLEX, PARAMETER :: iv = (a1,a2)
is no good. The CMPLX constructor cannot be used in initialisation expressions.

Complex values can be constructed elsewhere using the CMPLX intrinsic function,

    z = CMPLX(x,y)
This format must be used if the RHS is not a literal constant. It is recommended that the CMPLX intrinsic be used even when the RHS is a literal value (except in PARAMETER statements) as this makes the program more consistent and highlights the type conversion,
    z = CMPLX(3,6.9)
Type coercion behaves exactly as for the REAL data type, for example, if a COMPLEX literal contained integers, (1,1), these would be promoted to REAL values before assignment to the COMPLEX variable.

Complex expressions can be used in the same way as other types

   REAL :: x; COMPLEX :: a, b, c,
    ...
   a = x*((b+c)*CMPLX(0.1,-0.1))
   b = 1

The real value x will be promoted to the complex value CMPLX(x,0). b will be set to CMPLX(1.0,0). If necessary all other data types are promoted to complex values. When a non-complex value is coerced a 0.0 is placed in the complex part of the coordinate pair.

Return to corresponding overview page gif


next up previous contents
Next: Parameterised Intrinsic Types Up: Fortran 90 Previous: USE ONLY Statement

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.