COMPLEX_NUMBERS is a FORTRAN90 program which demonstrates very briefly some of the features of using complex numbers in a FORTRAN90 program.
The first issue is how to declare a complex variable, including the choice of single precision or double precision, whether the variable is a scalar, vector, or array, and whether the variable is initialized with a value, or assigned one.
A second issue concerns the question of how a complex variable is to be printed out.
Another issue concerns how a complex variable is to operated on by the arithmetic operators of addition, subtraction, multiplication, division, and exponentiation.
The language also provides a number of intrinsic functions that can be applied to a complex variable. The names of these functions can sometimes be easy to forget. Moreover, it is occasionally true that there may be a selection of functions with similar names (say, "exp", "cexp" and "dcexp") which may or may not produce the desired results.
Another issue concerns the details of double precision calculation. Even a single accidental use of a single precision function name in a double precision computation can result in the loss of half the digits of accuracy. Thus, it sometimes really matters whether you use "cmplx" or "dcmplx" to assign values to a double precision complex variable.
A peculiar feature of FORTRAN90 is that the generic cmplx() function will produce a result whose real and imaginary parts are single precision, no matter what the type of the input arguments or the target output value. The only ways to avoid this are to add the kind= qualifier, as in
a = cmplx ( b, c, kind = 8 )or to use the dcmplx() function specific to double precision:
a = dcmplx ( b, c )
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
COMPLEX_NUMBERS is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a Python version.
C4LIB, a FORTRAN90 library which implements certain elementary functions for "C4" or single precision complex variables;
C8LIB, a FORTRAN90 library which implements certain elementary functions for "C8" or double precision complex variables;
F90_INTRINSICS, FORTRAN90 programs which include some examples of the use of intrinsic functions included with the FORTRAN90 standard language.
GFORTRAN_INTRINSICS, FORTRAN90 programs which include some examples of the use of intrinsic functions included with the GFORTRAN compiler.
You can go up one level to the FORTRAN90 source codes.