C++ Complex Library - Imag



Description

It is an imaginary part of complex and returns the imaginary part of the complex number x.

Declaration

Following is the declaration for std::imag.

template<class T< T imag (const complex<T>& x);

C++11

template<class T> T imag (const complex<T>& x);

Parameters

x It is a complex value.

Return Value

It returns the imaginary part of the complex number x.

Exceptions

none

Example

In below example for std::imag.

#include <iostream>     
#include <complex>      

int main () {
   std::complex<double> mycomplex (50.0,12.0);
   std::cout << "Imaginary part is: " << std::imag(mycomplex) << '\n';
   return 0;
}

The sample output should be like this −

Imaginary part is: 12
complex.htm
Advertisements