template <class T> class complex;
Complex number class
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:
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.
- Complex number constructor (public member function)
- Return imaginary part (public member function)
- Return real part (public member function)
- complex operators
- Complex number operators (function)
The class also includes an alias type of the template argument:
- Value type (public member type)
is specialized for the three fundamental floating-point types: float
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
objects with different template argument).