|
|
The header <complex> defines the complex class, which represents complex numbers. It also defines a series of functions and operators that operate on objects of type complex.
The template specification for complex is shown here:
template <class T> class complex
Here, T specifies the type used to store the components of a complex number. There are three predefined specializations of complex:
class complex<float>
class complex<double>
class complex<long double>
The complex class has the following constructors:
complex(const T &real = T( ), const T = &imaginary = T( ));
complex(const complex &ob);
template <class T1> complex(const complex<T1> &ob);
The first constructs a complex object with a real component of real and an imaginary component of imaginary. These values default to zero if not specified. The second creates a copy of ob. The third creates a complex object from ob.
The following operations are defined for complex objects:
+ | – | * | / |
– = | += | /= | *= |
= | == | != |
The nonassignment operators are overloaded three ways: once for operations involving a complex object on the left and a scalar object on the right, again for operations involving a scalar on the left and a complex object on the right, and finally for operations involving two complex objects. For example, the following types of operations are allowed:
complex_ob + scalar
scalar + complex_ob
complex_ob + complex_ob
Operations involving scalar quantities affect only the real component.
Two member functions are defined for complex: real( ) and imag( ). They are shown here:
T real( ) const;
T imag( ) const;
The real( ) function returns the real component of the invoking object and imag( ) returns the imaginary component. The following functions are also defined for complex objects:
Function | Description |
---|---|
template <class T> | Returns the absolute value of ob |
template <class T> | Returns the phase angle of ob |
template <class T> complex<T> | Returns the conjugate of ob |
template <class T> | Returns the cosine of ob |
template <class T> | Returns the hyperbolic cosine of ob |
template <class T> | Returns the eob |
template <class T> | Returns the imaginary component of ob |
template <class T> | Returns the natural logarithm of ob |
template <class T> | Returns the base 10 logarithm of ob |
template <class T> | Returns the magnitude of ob squared |
template <class T> | Returns a complex number that has the magnitude specified by v and a phase angle of theta |
template <class T> | Returns be |
template <class T> | Returns be |
template <class T> | Returns be |
template <class T> | Returns be |
template <class T> | Returns the real component of ob |
template <class T> | Returns the sine of ob |
template <class T> | Returns the hyperbolic sine of ob |
template <class T> | Returns the square root of ob |
template <class T> | Returns the tangent of ob |
template <class T> | Returns the hyperbolic tangent of ob |
|
|