std::arg(std::complex)

来自cppreference.com
< cpp‎ | numeric‎ | complex
定义于头文件 <complex>
template< class T >
T arg( const complex<T>& z );
(1)
long double arg( long double z );
(2) (C++11 起)
template< class DoubleOrInteger >
double arg( DoubleOrInteger z );
(3) (C++11 起)
float arg( float z );
(4) (C++11 起)

计算复数 z 的辐角(以弧度表示)

(C++11 起)floatdoublelong double 及所有整数类型提供重载,它们被当做有零虚部的复数

参数

z - 复数值

返回值

若无错误发生,则返回 z 在区间 (−π; π) 内的辐角。

错误和特殊情况按照函数宛如以 std::atan2(std::imag(z), std::real(z)) 实现来处理。

示例

#include <iostream>
#include <complex>
 
int main() 
{
    std::complex<double> z1(1, 0); 
    std::cout << "phase angle of " << z1 << " is " << std::arg(z1) << '\n';
 
    std::complex<double> z2(0, 1); 
    std::cout << "phase angle of " << z2 << " is " << std::arg(z2) << '\n';
 
    std::complex<double> z3(-1, 0); 
    std::cout << "phase angle of " << z3 << " is " << std::arg(z3) << '\n';
 
    std::complex<double> z4(-1, -0.0); 
    std::cout << "phase angle of " << z4 << " (the other side of the cut) is "
              << std::arg(z4) << '\n';
}

输出:

phase angle of (1,0) is 0
phase angle of (0,1) is 1.5708
phase angle of (-1,0) is 3.14159
phase angle of (-1,-0) (the other side of the cut) is -3.14159

参阅

返回复数的模
(函数模板)
从模和辐角构造复数
(函数模板)
(C++11)(C++11)
反正切,用符号确定象限
(函数)
应用函数 std::atan2 到一个 valarray 和一个值
(函数模板)