◐ Shell
clean mode source ↗

std::real(std::complex) - cppreference.com

来自cppreference.com

在标头 <complex> 定义

template< class T > 
T real( const std::complex<T>& z );
(1) (C++14 前)
template< class T > 
constexpr T real( const std::complex<T>& z );
(C++14 起)

额外重载 (C++11 起)

在标头 <complex> 定义

float       real( float f );
double      real( double f );
long double real( long double f );
(A) (C++14 前)
constexpr float       real( float f );
constexpr double      real( double f );
constexpr long double real( long double f );
(C++14 起)
(C++23 前)
template< class FloatingPoint >
constexpr FloatingPoint real( FloatingPoint f );
(C++23 起)
template< class Integer >
double real( Integer i );
(B) (C++14 前)
template< class Integer >
constexpr double real( Integer i );
(C++14 起)

1) 返回复数 z 的实部,即 z.real()

A,B) 为所有整数和浮点类型提供额外重载,它们被处理为拥有零虚部的复数。

(C++11 起)

参数

返回值

1) z 的实部。

A) f

B) static_cast<double>(i)

注解

额外重载不需要严格以 (A,B) 的形式提供。它们只需要能够对它们的实参 num 满足以下要求即可:

  • 如果 num 具有标准(C++23 前)浮点类型 T,那么 std::real(num)std::real(std::complex<T>(num)) 的效果相同。
  • 否则,如果 num 具有整数类型,那么 std::real(num)std::real(std::complex<double>(num)) 的效果相同。

参阅