C4_COMPLEX_LIB
A Single Precision Complex Arithmetic Utility Library


C4_COMPLEX_LIB, a C library which contains routines for "C4" or "single precision complex" arithmetic.

The original C specification did not include support for complex numbers. Until the later C99 specification added such support, it was common for programmers to develop their own complex arithmetic libraries. Despite the fact that these routines are now generally obsolete, the procedures involved can still be instructive and useful, including the use of structures for the data type and the development of a variety of functions to carry out the necessary arithmetic operations.

To use the structures and functions of this library, it is necessary that the user's source code invoke the include file:


        # include "c4_complex_lib.h"
      

This package defines a single precision complex number as a C struct whose components are floats:


        struct c4_complex
        {
          float real;
          float imag;
        };
      

To declare a variable c you could use a statement like:


        struct c4_complex c;
      

The declaration can include an initialization:


        struct c4_complex c = { 1.0, 2.0 };
      

The value of a variable c declared as struct c4_complex may be examined or changed by accessing the components of the struct. Thus, the initialization above could be carried out at run time by the commands:


        c.real = 1.0;
        c.imag = 2.0;
      

In the common case when pointers are used, we declare


        struct *c4_complex c;
      
and then create the variable with:

        c = ( struct c4_complex *) malloc ( sizeof ( struct c4_complex ) );
      
and assign values with commands like:

        c->real = 1.0;
        c->imag = 2.0;
      
and finally, release the memory associated with the variable by

        free ( c );
      

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

C4_COMPLEX_LIB is available in a C version and a C++ version.

Related Programs:

BLAS1_C, a C library which contains basic linear algebra routines for vector-vector operations, using single precision complex arithmetic.

c4_complex_lib_test

C4LIB, a C library which implements certain elementary functions for "C4" or single precision complex variables using the C99 "float complex" datatype.

C8_COMPLEX_LIB, a C library which defines a double precision complex variable or "C8" as a structure, and implements certain corresponding elementary functions.

COMPLEX_NUMBERS, a C program which demonstrates some simple features involved in the use of complex numbers in C programming.

I4LIB, a C library which contains many utility routines, using "I4" or "single precision integer" arithmetic.

I8LIB, a C library which contains many utility routines, using "I8" or "double precision integer" arithmetic.

R4LIB, a C library which contains many utility routines, using "R4" or "single precision real" arithmetic.

R8LIB, a C library which contains many utility routines, using "R8" or "double precision real" arithmetic.

Source Code:


Last revised on 12 June 2019.