# C4_COMPLEX_LIB A Single Precision Complex Arithmetic Utility Library

C4_COMPLEX_LIB is 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 );
``````

### 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.

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.

### List of Routines:

• C4_ABS returns the absolute value of a C4.
• C4_ACOS evaluates the inverse cosine of a C4.
• C4_ACOSH evaluates the inverse hyperbolic cosine of a C4.
• C4_ARG returns the argument of a C4.
• C4_ASIN evaluates the inverse sine of a C4.
• C4_ASINH evaluates the inverse hyperbolic sine of a C4.
• C4_ATAN evaluates the inverse tangent of a C4.
• C4_ATANH evaluates the inverse hyperbolic tangent of a C4.
• C4_CONJ conjugates a C4.
• C4_COPY copies a C4.
• C4_COS evaluates the cosine of a C4.
• C4_COSH evaluates the hyperbolic cosine of a C4.
• C4_CUBE_ROOT computes the principal cube root of a C4.
• C4_DIV divides two C4's.
• C4_DIV_R4 divides a C4 by an R4.
• C4_EXP exponentiates a C4.
• C4_I returns the value of I as a C4
• C4_IMAG returns the imaginary part of a C4.
• C4_INV inverts a C4.
• C4_LOG evaluates the logarithm of a C4.
• C4_MAG returns the magnitude of a C4.
• C4_MUL multiplies two C4's.
• C4_NEG negates a C4.
• C4_NORMAL_01 returns a unit pseudonormal C4.
• C4_ONE returns the value of 1 as a C4
• C4_REAL returns the real part of a C4.
• C4_SIN evaluates the sine of a C4.
• C4_SINH evaluates the hyperbolic sine of a C4.
• C4_SQRT computes a square root of a C4.
• C4_SUB subtracts two C4's.
• C4_SWAP swaps two C4's.
• C4_TAN evaluates the tangent of a C4.
• C4_TANH evaluates the hyperbolic tangent of a C4.
• C4_TO_CARTESIAN converts a C4 to Cartesian form.
• C4_TO_POLAR converts a C4 to polar form.
• C4_UNIFORM_01 returns a unit pseudorandom C4.
• C4_ZERO returns the value of 0 as a C4
• CARTESIAN_TO_C4 converts a Cartesian form to a C4.
• POLAR_TO_C4 converts a polar form to a C4.
• R4_UNIFORM_01 returns a unit pseudorandom R4.
• SORT_HEAP_EXTERNAL externally sorts a list of items into ascending order.
• TIMESTAMP prints the current YMDHMS date as a time stamp.

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

Last revised on 06 October 2010.