C4LIB
A Float Precision Complex Arithmetic Utility Library


C4LIB is a C library which contains routines for "C4" or "float complex" arithmetic.

The original C specification did not include support for complex numbers. The "C99" version of the ANSI standard added specifications for a complex number datatype with either float, double and long double components, the extension of existing arithmetic operations and functions to the new datatypes and the addition of a number of new functions unique to complex numbers.

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


        # include 
      

A complex number may be declared as

The constant I is defined to be equal to the imaginary unit. To assign a numeric value to a complex number, you must multiply the imaginary part by I:


        float complex c;

        c = 3 + 4 * I;
      

The declaration can include an initialization:


        float complex c = 3 - 4 * I;
      

To examine the real or imaginary parts of a complex variable, the functions creal() and cimag() can be used:


        float complex c = 3 + 4 * I;
        printf ( "  Expecting value 3, got %f\n", creal ( c ) );
        printf ( "  Expecting value 4, got %f\n", cimag ( c ) );
      

There are 22 functions defined for float complex, double complex, and long double complex data types. Here are the headers for the float complex functions:
FunctionValue
float = cabs(float complex)absolute value of c
float complex = cacos(float complex)inverse cosine of c
float complex = cacosh(float complex)inverse hyperbolic cosine of c
float = carg(float complex)argument of c
float complex = casin(float complex)inverse sine of c
float complex = casinh(float complex)inverse hyperbolic sine of c
float complex = catan(float complex)inverse tangent of c
float complex = catanh(float complex)inverse hyperbolic tangent of c
float complex = ccos(float complex)cosine of c
float complex = ccosh(float complex)hyperbolic cosine of c
float complex = cexp(float complex)exponential of c
float = cimag(float complex)imaginary part of c
float complex = clog(float complex)logarithm of c
float complex = conj(float complex)conjugate of c
float complex = cpow(float complex, float complex)c1 to the c2 power
float complex = cproj(float complex)projection of c onto Riemann sphere
float = creal(float complex)real part of c
float complex = csin(float complex)sine of c
float complex = csinh(float complex)hyperbolic sine of c
float complex = csqrt(float complex)square root of c
float complex = ctan(float complex)tangent of c
float complex = ctanh(float complex)hyperbolic tangent of c

C4LIB, in part, duplicates some of the functionality that was added by the C99 standard. The C4LIB versions should be of historical interest only. Other functions provided by C4LIB, however, may be of more substantial interest.

Licensing:

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

Languages:

C4LIB is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version.

Related Programs:

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

C4_COMPLEX_LIB, a C library which defines a single precision complex variable or "C4" as a structure, and implements certain corresponding elementary functions.

C8LIB, a C library which implements certain elementary functions for "C8" or double precision complex variables using the C99 standard "double complex" datatype.

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.

L4LIB, a C library which contains many utility routines, using one byte logical (L4) variables.

MY_COMPLEX, a C++ class for complex numbers;

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:

Examples and Tests:

List of Routines:

You can go up one level to the C source codes.


Last revised on 09 March 2014.