class template
<complex>
std::complex
template <class T> class complex;
Complex number class
The
complex class is designed to hold two components of the same type, that conform a complex number.
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
i, known as the imaginary unit, and which satisfies that:
i
2 = -1
In this class, complex numbers have two components:
real (corresponding to
x in the above example) and
imag (corresponding to
y). This way of referring to complex numbers by two real components is known and cartesian, because this way they have the ability to be easily representable on a cartesian axis.
The class has been implemented to provide as similar a functionality as the one of a numerical type when this was possible, therefore,
complex objects can be assigned, compared, inserted and extracted, as well as several arithmetical operators have been overloaded to be used on them directly.
Members
- (constructor)
- Complex number constructor (public member function)
- complex::imag
- Return imaginary part (public member function)
- complex::real
- Return real part (public member function)
- complex operators
- Complex number operators (function)
The class also includes an alias type of the template argument:
- complex::value_type
- Value type (public member type)
complex specializations
complex is specialized for the three fundamental floating-point types:
float,
double and
long double.
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 objects with different template argument).