[an error occurred while processing this directive] [an error occurred while processing this directive]
[an error occurred while processing this directive] Skip to the content of the web site.The C++ classes Complex<long double>, Complex<double>, and Complex<float> represent floating-point complex numbers of the form z = a + ib. Throughout this document, the variable z = a + ib is used to represent *this object. The template variable T represents the field of the coefficients.
There is one constructor
Complex( T a = 0, T b = 0 );
which creates the complex number a + ib.
There are three static constants defined in each class:
ZERO | 0 |
ONE | 1 |
I | i |
The constants may be accessed through the array UNITS[2] = {ONE, I}.
Each of the real-valued member functions has the prototype T f() const; and has a corresponding procedural function T f( const Complex<T> );.
real | imag_i | csgn | abs |
norm | abs_imag | norm_imag | arg |
Descriptions of each of the functions follow:
The function T operator [](int n) const returns the coefficient of the unit UNITS[n] for n = 0 and 1.
Each of these complex-valued member functions has the prototype Complex<T> f() const; and has a corresponding procedural function Complex<T> f( const Complex<T> );.
imag | conj | signum |
Descriptions of each of the functions follow:
Each of the square, square root, and inverse member functions has the prototype Complex<T> f() const; and has a corresponding procedural function Complex<T> f( const Complex<T> );.
sqr | sqrt | inverse |
Descriptions of each of the functions follow:
As spherical (or imaginary) rotations do not apply for complex numbers, there is no Complex<T> rotate( Complex<T> ) member function.
The power function is overloaded with two prototypes:
Complex<T> pow( T ) | Complex<T> pow( Complex<T> ) |
Each of the exponential and logarithmic member functions has the prototype Complex<T> f() const; and has a corresponding procedural function Complex<T> f( const Complex<T> );.
exp | log | log10 |
Descriptions of each of the functions follow:
Each of the trigonometric, hyperbolic, inverse trigonometric, and inverse hyperbolic member functions has the prototype Complex<T> f() const; and has a corresponding procedural function Complex<T> f( const Complex<T> );.
sin | cos | tan | sec | csc | cot |
sinh | cosh | tanh | sech | csch | coth |
asin | acos | atan | asec | acsc | acot |
asinh | acosh | atanh | asech | acsch | acoth |
For example, the sin function calculates the result of z − z3/3! + z5/5! − z7/7! + z9/9! − z11/11! + ⋅⋅⋅ by using the formula:
Bessel functions of the first kind, Jn(z) are implemented for integer values of n. The prototype of the member function is Complex<T> bessel_J( int ) const; and there is the corresponding procedural function Complex<T> bessel_J( int, const Complex<T>) const;.
Each of the integer-valued member functions has the prototype Complex<T> f() const; and has a corresponding procedural function Complex<T> f( const Complex<T> );.
floor | ceil |
In both cases, the floor and ceiling, respectively, are calculated for each component.
The polynomial v0zn − 1 + v1zn − 2 + v2zn − 3 + ⋅⋅⋅ vn − 3z2 + vn − 2z + vn − 1 may be calculated efficiently using Horner's rule. The array v of n entries may be either of type Complex<T> * or T *.
Complex<T> horner( T * v, unsigned int n ); Complex<T> horner( Complex<T> * v, unsigned int n );
The Newton polynomial with offsets:
v0(z − cn − 1)(z − cn − 2)⋅⋅⋅(z − c3)(z − c2)(z − c1) +
v1(z − cn − 1)(z − cn − 2)⋅⋅⋅(z − c3)(z − c2) +
v2(z − cn − 1)(z − cn − 2)⋅⋅⋅(z − c3) + ⋅⋅⋅ +
vn − 3(z − cn − 1)(z − cn − 2) +
vn − 2(z − cn − 1) +
vn − 1 may also be
calculated efficiently using Horner's rule. The arrays v and c of n entries
may be either of type Complex<T> * or T *.
Complex<T> horner( T * v, T * c, unsigned int n ); Complex<T> horner( Complex<T> * v, T * c, unsigned int n ); Complex<T> horner( T * v, Complex<T> * c, unsigned int n ); Complex<T> horner( Complex<T> * v, Complex<T> * c, unsigned int n );
Corresponding to each of these functions is a procedural function which takes the variable z as a first argument.
All binary arithmetic operators operator ⋅ have the following prototypes:
operator ⋅ ( const Complex<T> &, const Complex<T> & ), operator ⋅ ( T, const Complex<T> & ), and operator ⋅ ( const Complex<T> &, T ). The standard operations are:+ | - | * | / |
The unary arithmetic operator operator - has the prototype operator - ( const Complex<T> & ) and returns the negative of the complex number.
The assignment operators operator ⋅ have the prototypes operator ⋅ ( const Complex<T> & ) and operator ⋅ ( T ) and appropriately modifies and returns this complex number. The operations are:
= | += | -= | *= | /= |
The auto increment and auto decrement operators work on the real part of the complex number.
All binary Boolean operators have the following prototypes:
operator ⋅ ( const Complex<T> &, const Complex<T> & ), operator ⋅ ( T, const Complex<T> & ), and operator ⋅ ( const Complex<T> &, T ). The standard operations are:== | != |
Descriptions of each of the functions follow:
Each of the following member functions has the prototype bool f() const; and returns a value based on the components of this complex number.
is_imaginary | is_inf | is_nan | is_neg_inf |
is_pos_inf | is_real | is_real_inf | is_zero |
Descriptions of each of the functions follow:
Each of the following static factory functions has the prototype static Complex<T> f() const; and returns a random complex number according to the following definitions:
where rk is a random real value.
The stream operators have been overloaded to print and read complex numbers.
The character used to displayed by the stream operators may be set using the static functions with prototypes char use_symbol( char sym ); and char get_symbol();.