std:: arg (std::complex)
From cppreference.net
|
定义于头文件
<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)
为所有整数和浮点类型提供了额外的重载,这些类型被视为虚部为零的复数。
|
(since 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)
|
反正切函数,使用符号确定象限
(函数) |
|
对 valarray 和值应用函数
std::atan2
(函数模板) |
|
|
C documentation
for
carg
|
|