名稱空間
變體
操作

std::real(std::complex)

來自 cppreference.com
< cpp‎ | 數值‎ | 複數
 
 
 
 
定義於標頭檔案 <complex>
(1)
template< class T >
T real( const std::complex<T>& z );
(直到 C++14)
template< class T >
constexpr T real( const std::complex<T>& z );
(C++14 起)
額外過載 (自 C++11 起)
定義於標頭檔案 <complex>
(A)
float       real( float f );

double      real( double f );

long double real( long double f );
(直到 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 起)
(B)
template< class Integer >
double real( Integer i );
(直到 C++14)
template< class Integer >
constexpr double real( Integer i );
(C++14 起)
1) 返回複數 z 的實部,即 z.real()
A,B) 為所有整數和浮點型別提供了額外的過載,這些型別被視為虛部為零的複數。
(C++11 起)

目錄

[edit] 引數

z - 複數型別的值
f - 浮點值
i - 整數值

[edit] 返回值

1) z 的實部。
A) f
B) static_cast<double>(i)

[edit] 注意

不需要完全按照 (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)) 相同的效果。

[edit] 另請參閱

訪問複數的實部
(公共成員函式) [edit]
返回虛部
(函式模板) [edit]
C 文件 關於 creal