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.

- Constructors
- Constants
- Real-Valued Functions
- Complex-Valued Functions
- Squares and Inverses
- Rotations
- Powers
- Exponential and Logarithmic Functions
- Trigonometric and Hyperbolic Functions (and their Inverses)
- Special Functions
- Integer-Value Functions
- Horner's Rule
- Binary Arithmetic Operators
- Unary Arithmetic Operators
- Assignment Operators
- Auto Increment and Auto Decrement Operators
- Binary Boolean Operators
- Query Functions
- Static Factory Functions
- Stream Operators

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:

`real`- Return the real component ℜ(
*z*) =*a*. `imag_i`- Return the imaginary component ℑ(
*z*) =*b*. `csgn`- Return 0 if
*z*= 0, 1 if*a*≥ +0, and -1 if*a*≤ -0. `abs`- Return |
*z*| = (*a*^{2}+*b*^{2})^{½}unless either component is infinity, in which case, it always returns ∞. `norm`- Return |
*z*|^{2}=*a*^{2}+*b*^{2}unless either component is infinity, in which case, it always returns ∞. `abs_imag`- Return |ℑ(
*z*)| = |*b*|. `norm_imag`- Return |ℑ(
*z*)|^{2}=*b*^{2}. `arg`- Return the argument of the complex number arg(
*z*) = atan2(*b*,*a*).

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:

`imag`- Returns the complex number 0 +
*ib*. `cong`- Returns the complex number
*a*−*ib*. `signum`- Returns the complex number
*z*/|*z*|. If*z*= 0, then*z*is returned.

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:

`sqr`- Calculate
*z*^{2}. `sqrt`- Calculate the square root of
*z*(that is,*z*^{½}). `inverse`- Calculate the inverse of
*z*(that is,*z*^{-1}).

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:

`exp`- Calculate
*e*^{z}. `log`- Calculate the natural logarithm ln(
*z*). `log10`- Calculate the base-10 logarithm log
_{10}(*z*).

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* − *z*^{3}/3! + *z*^{5}/5! − *z*^{7}/7! + *z*^{9}/9! − *z*^{11}/11! + ⋅⋅⋅ by using the formula:

Bessel functions of the first kind, J_{n}(*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
*v*_{0}*z*^{n − 1} +
*v*_{1}*z*^{n − 2} +
*v*_{2}*z*^{n − 3} + ⋅⋅⋅
*v*_{n − 3}*z*^{2} +
*v*_{n − 2}*z* +
*v*_{n − 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:
*v*_{0}(*z* − c_{n − 1})(*z* − c_{n − 2})⋅⋅⋅(*z* − c_{3})(*z* − c_{2})(*z* − c_{1}) +

*v*_{1}(*z* − c_{n − 1})(*z* − c_{n − 2})⋅⋅⋅(*z* − c_{3})(*z* − c_{2}) +

*v*_{2}(*z* − c_{n − 1})(*z* − c_{n − 2})⋅⋅⋅(*z* − c_{3}) + ⋅⋅⋅ +

*v*_{n − 3}(*z* − c_{n − 1})(*z* − c_{n − 2}) +

*v*_{n − 2}(*z* − c_{n − 1}) +

*v*_{n − 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:

+ |
- |
* |
/ |

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:

== |
!= |

Descriptions of each of the functions follow:

`operator ==`- Returns
`true`if both components return true under`==`. `operator !=`- Returns
`true`if any components return true under`!=`.

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:

`is_imaginary`- Returns
`true`if this complex number has a zero real component (of the form 0 +*bi*) and`false`otherwise. `is_inf`- Returns
`true`if either component of this is one of either +∞ or -∞ and`false`otherwise. `is_nan`- Returns
`true`if either component of this is`NaN`and`false`otherwise. `is_neg_inf`- Returns
`true`if this complex number is -∞ + 0i and`false`otherwise. `is_pos_inf`- Returns
`true`if this complex number is ∞ + 0i and`false`otherwise. `is_real`- Returns
`true`if this complex number has a zero imaginary component (of the form*a*+ 0*i*) and`false`otherwise. `is_real_inf`- Returns
`true`if this complex number is either +∞ + 0i or -∞ + 0i and`false`otherwise. `is_zero`- Returns
`true`if this complex number is 0 + 0i and`false`otherwise.

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:

`random`*r*_{1}+ i*r*_{2}`random_real`*r*_{1}+ i0`random_imag`- 0 + i
*r*_{1}

where *r*_{k} 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();`.