c8lib, a C code which contains routines for "C8" or "double 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 <complex.h>
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:
double complex c;
c = 3 + 4 * I;
The declaration can include an initialization:
double complex c = 3 - 4 * I;
To examine the real or imaginary parts of a complex variable, the functions creal() and cimag() can be used:
double 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 double complex functions:
Function | Value |
---|---|
double = cabs(double complex) | absolute value of c |
double complex = cacos(double complex) | inverse cosine of c |
double complex = cacosh(double complex) | inverse hyperbolic cosine of c |
double = carg(double complex) | argument of c |
double complex = casin(double complex) | inverse sine of c |
double complex = casinh(double complex) | inverse hyperbolic sine of c |
double complex = catan(double complex) | inverse tangent of c |
double complex = catanh(double complex) | inverse hyperbolic tangent of c |
double complex = ccos(double complex) | cosine of c |
double complex = ccosh(double complex) | hyperbolic cosine of c |
double complex = cexp(double complex) | exponential of c |
double = cimag(double complex) | imaginary part of c |
double complex = clog(double complex) | logarithm of c |
double complex = conj(double complex) | conjugate of c |
double complex = cpow(double complex, double complex) | c1 to the c2 power |
double complex = cproj(double complex) | projection of c onto Riemann sphere |
double = creal(double complex) | real part of c |
double complex = csin(double complex) | sine of c |
double complex = csinh(double complex) | hyperbolic sine of c |
double complex = csqrt(double complex) | square root of c |
double complex = ctan(double complex) | tangent of c |
double complex = ctanh(double complex) | hyperbolic tangent of c |
C8LIB, in part, duplicates some of the functionality that was added by the C99 standard. The C8LIB versions should be of historical interest only. Other functions provided by C8LIB, however, may be of more substantial interest.
The computer code and data files described and made available on this web page are distributed under the MIT license
c8lib is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and a Python version..
BLAS1_Z, a C code which contains basic linear algebra routines for vector-vector operations, using double precision complex arithmetic.
C4LIB, a C code which implements certain elementary functions for "C4" or single precision complex variables using the C99 "float complex" datatype.
C8_COMPLEX_LIB, a C code which defines a double precision complex variable or "C8" as a structure, and implements certain corresponding elementary functions.
COMPLEX_NUMBERS, a C code which demonstrates some simple features involved in the use of complex numbers in C codeming.
I4LIB, a C code which contains many utility routines, using "I4" or "single precision integer" arithmetic.
I8LIB, a C code which contains many utility routines, using "I8" or "double precision integer" arithmetic.
L4LIB, a C code which contains many utility routines, using one byte logical (L4) variables.
R4LIB, a C code which contains many utility routines, using "R4" or "single precision real" arithmetic.
R8LIB, a C code which contains many utility routines, using "R8" or "double precision real" arithmetic.