function template
<complex>

std::real

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

The function returns the same as if calling: x.real().
The function returns the same as if calling: x.real() 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 simply returns x converted to the proper type.
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

Real 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::real example
#include <iostream>     // std::cout
#include <complex>      // std::complex, std::real

int main ()
{
  std::complex<double> mycomplex (10.0,1.0);

  std::cout << "Real part: " << std::real(mycomplex) << '\n';

  return 0;
}

Output:

Real part: 10


See also