std::arg(std::complex)
來自 cppreference.com
定義於標頭檔案 <complex> |
||
template< class T > T arg( const std::complex<T>& z ); |
(1) | |
額外過載 (自 C++11 起) |
||
定義於標頭檔案 <complex> |
||
(A) | ||
float arg( float f ); double arg( double f ); |
(直至 C++23) | |
template< class FloatingPoint > FloatingPoint |
(C++23 起) | |
template< class Integer > double arg( Integer i ); |
(B) | |
1) 計算複數 z 的相位角(弧度)。
A,B) 為所有整數和浮點型別提供了額外的過載,這些型別被視為虛部為零的複數。
|
(C++11 起) |
目錄 |
[編輯] 引數
z | - | 複數型別的值 |
f | - | 浮點值 |
i | - | 整數值 |
[編輯] 返回值
A) 如果 f 為正或 +0,則為零;如果 f 為負或 -0,則為 π;否則為 NaN。
B) 如果 i 為非負數,則為零;如果為負數,則為 π。
[編輯] 註解
不需要完全按照 (A,B) 提供額外的過載。它們只需要足以確保對於它們的引數 num
- 如果 num 擁有標準(C++23 前)浮點型別
T
,則 std::arg(num) 的效果與 std::arg(std::complex<T>(num)) 相同。 - 否則,如果 num 擁有整數型別,則 std::arg(num) 的效果與 std::arg(std::complex<double>(num)) 相同。
[編輯] 示例
執行此程式碼
#include <complex> #include <iostream> int main() { std::complex<double> z1(1, 0); std::complex<double> z2(0, 0); std::complex<double> z3(0, 1); std::complex<double> z4(-1, 0); std::complex<double> z5(-1, -0.0); double f = 1.; int i = -1; std::cout << "phase angle of " << z1 << " is " << std::arg(z1) << '\n' << "phase angle of " << z2 << " is " << std::arg(z2) << '\n' << "phase angle of " << z3 << " is " << std::arg(z3) << '\n' << "phase angle of " << z4 << " is " << std::arg(z4) << '\n' << "phase angle of " << z5 << " is " << std::arg(z5) << " " "(the other side of the cut)\n" << "phase angle of " << f << " is " << std::arg(f) << '\n' << "phase angle of " << i << " is " << std::arg(i) << '\n'; }
輸出
phase angle of (1,0) is 0 phase angle of (0,0) is 0 phase angle of (0,1) is 1.5708 phase angle of (-1,0) is 3.14159 phase angle of (-1,-0) is -3.14159 (the other side of the cut) phase angle of 1 is 0 phase angle of -1 is 3.14159
[編輯] 參閱
返回複數的模 (函式模板) | |
從模和相角構造一個複數 (函式模板) | |
(C++11)(C++11) |
反正切,使用符號確定象限 (函式) |
將函式 std::atan2 應用於一個 valarray 和一個值 (函式模板) | |
C 文件 關於 carg
|