Export (0) Print
Expand All

complex::imag

Extracts the imaginary component of a complex number.

Type imag( ) const;
Type imag(const Type& _Right);

_Right

A complex number whose imaginary value is to be extracted.

The imaginary part of the complex number.

For a complex number a + bi, the imaginary part or component is Im(a + bi) = b.

// complex_imag.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>

int main( )
{
   using namespace std;

   complex <double> c1 ( 4.0 , 3.0 );
   cout << "The complex number c1 = " << c1 << endl;

   double dr1 = c1.real ( );
   cout << "The real part of c1 is c1.real ( ) = "
        << dr1 << "." << endl;

   double di1 = c1.imag ( );
   cout << "The imaginary part of c1 is c1.imag ( ) = "
        << di1 << "." << endl;
}
The complex number c1 = (4,3)
The real part of c1 is c1.real ( ) = 4.
The imaginary part of c1 is c1.imag ( ) = 3.

Header: <complex>

Namespace: std

Show:
© 2015 Microsoft