std::arg(std::complex)
来自 cppreference.cn
定义于头文件 <complex> |
||
template< class T > T arg( const std::complex<T>& z ); |
(1) | |
附加重载 (since C++11) |
||
定义于头文件 <complex> |
||
(A) | ||
float arg( float f ); double arg( double f ); |
(until C++23) | |
template< class FloatingPoint > FloatingPoint |
(since 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) |
反正切,使用符号确定象限 (函数) |
将函数 std::atan2 应用于 valarray 和一个值 (函数模板) | |
C 文档 关于 carg
|