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:
i2 = -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.
|(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 (functions)|
The class also includes an alias type of the template argument:
|complex::value_type||Value type (public member type)|
complex specializationscomplex 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).