Complex numbers library
The complex library implements theClasses
complex | Complex number class |
Functions
Complex values:real | Return real part of complex |
imag | Return imaginary part of complex |
abs | Return absolute value of complex |
arg | Return phase angle of complex |
norm | Return norm of complex number |
conj | Return complex conjugate |
polar | Return complex from polar components |
Transcendentals overloads:
cos | Return cosine of complex |
cosh | Return hyperbolic cosine of complex |
exp | Return exponential of complex |
log | Return natural logarithm of complex |
log10 | Return common logarithm of complex |
pow | Return complex power |
sin | Return sine of complex |
sinh | Return hyperbolic sine of complex |
sqrt | Return square root of complex |
tan | Return tangent of complex |
tanh | Return hyperbolic tangent of complex |
Operator overloads:
complex operators | Complex number operators |
complex
<complex>
template <class T> class complex;
Complex number class
The
A complex number is formed by adding an imaginary part to a real number:
x + y * i
The imaginary part (y*i) is a factor of
i2
In this class, complex numbers have two components:
The class has been implemented to provide as similar a functionality as the one of a numerical type when this was possible, therefore,
Members
(constructor) | Complex number constructor |
complex::imag | Return imaginary part |
complex::real | Return real part |
complex operators | Complex number operators |
The class also includes an alias type of the template argument:
complex::value_type | Value type |
complex specializations
complex
These specializations have the same members as the template, but optimize its implementation for these fundamental types, as well as they allow operations with other instantiations of
complex::complex
complex (const T& re = T(), const T& im = T()); complex (const complex& cmplx); template<class X> complex (const complex<X>& cmplx);
Complex number constructor
Constructs a
It may be constructed from two values (re
Parameters
-
re, im
-
Real and imaginary parts, respectively, of complex number.
Tis complex's template type.
cmplx
-
A
complex object.
If constructed from acomplex object with a different template parameter (X), the apropriate conversions are performed.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Output:
(2,2) |
complex::real
T real() const;
Return real part
Returns theA global function exists,
Parameters
noneReturn value
Real part.T
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Output:
Real part: 10 |
complex::imag
T imag() const;
Return imaginary part
Returns theThe imaginary part is the factor by which the imaginary unit is multiplied.
A global function exists,
Parameters
noneReturn value
Imaginary part.T
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Output:
Imaginary part: 2 |