Share via


complex::real

Gets or sets the real component of a complex number.

constexpr T real( ) const;
T real(const T& Right);

Parameters

  • Right
    A complex number whose real value is to be extracted.

Return Value

The real part of the complex number.

Remarks

For a complex number a + bi, the real part or component is Re(a + bi) = a.

Example

// complex_class_real.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.

Requirements

Header: <complex>

Namespace: std

See Also

Reference

complex Class