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

参数

x
Complex value.

返回值

Imaginary part of x.
Tcomplex 类型的分量类型(即其值类型)。

示例

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;
}

输出

Imaginary part: 2


另见