class template
<complex>

std::complex

template <class T> class complex;
Complex number class
The complex class is designed to hold two elements of the same type representing a complex number in its Cartesian form.

A complex number can be represented by the sum of a real number (x) and an imaginary part (y*i):

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).

The class replicates certain functionality aspects of regular numerical types, allowing them to be assigned, compared, inserted and extracted, as well as supporting some arithmetical operators. It is a literal type internally organized as an array of two elements of type T: the first is the real part and the second its imaginary part.

Template parameters

T
Type of both the real and imaginary components of the complex number.
The effect of instantiating a complex with a T other than float, double or long double is undefined (certain library implementations may support it, but the resulting code is non-portable).

Member types

member typedefinitiondescription
value_typeThe first template parameter (T)The type of both Cartesian components

Member functions


Template 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 allowing operations with the other specializations of complex (complex objects with a different template argument).