function template
<complex>

std::imag

complex (1)
template<class T> T imag (const complex<T>& x);
complex (1)
template<class T> T imag (const complex<T>& x);
arithmetic type (2)
double imag (ArithmeticType x);  // additional overloads
Imaginary part of complex
Returns the imaginary part of the complex number x.

The imaginary part is the factor by which the imaginary unit is multiplied.

The function returns the same as if calling: x.imag().
The function returns the same as if calling: x.imag() for (1).

Additional overloads (2) are provided for arguments of any fundamental arithmetic type: In this case, the function assumes the value has a zero imaginary component, and thus returns zero.
The return type is double, except if the argument is float or long double (in which case, the return type is of the same type as the argument).

Parameters

x
Complex value.

Return value

Imaginary part of x.
T is the type of the components of the complex type (i.e., its value type).

Example

1
2
3
4
5
6
7
8
9
10
11
12
// std::imag example
#include <iostream>     // std::cout
#include <complex>      // std::complex, std::imag

int main ()
{
  std::complex<double> mycomplex (20.0,2.0);

  std::cout << "Imaginary part: " << std::imag(mycomplex) << '\n';

  return 0;
}

Output:

Imaginary part: 2


See also