C4_COMPLEX_LIB is a C++ library which defines complex numbers and the operations necessary to do arithmetic on them.
Since the ANSI C++ standard library now includes a complex class, the information described here is probably not of practical use. On the other hand, it may be helpful as a practical demonstration of how to define a useful arithmetic class.
The C4_COMPLEX class defines a c4_complex number as a pair of floats. A variable c in this class may be declared by
c4_complex c;
The declaration can include an initialization:
c4_complex c = c4_complex ( 1.0, 2.0 );
A variable c declared as c4_complex may be assigned a value using the c4_complex() function:
c = c4_complex ( a, b )
where a and b are float values; the assignment
c = c4_complex ( a )
sets the real part of c to a, and the imaginary part to 0.
A variable c declared as c4_complex may be used in addition, subtraction, multiplication, or division with another c4_complex value, or a float value:
c3 = c1 + c2;
c3 = c1 - c2;
c3 = c1 * c2;
c3 = c1 / c2;
A variable c declared as c4_complex may be conjugated, or its real or imaginary part may be produced as a float value:
c2 = ~c;
d1 = c1.real ( );
d2 = c1.imaginary ( );
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
C4_COMPLEX_LIB is available in a C version and a C++ version.
C4LIB,
a C++ library which
implements certain elementary functions for "C4"
or single precision complex variables
using the C++ "complex
C8_COMPLEX_LIB, a C++ library which defines a class called c8_complex for complex numbers with double precision components.
CPP, C++ programs which includes an example of the declaration and use of complex variables.
You can go up one level to the C++ source codes.