complex_arg
complex_arg (복소수의 위상각)
복소수 z의 위상각(편각, 라디안 단위)을 구하는 함수예요. 정수·부동소수점 타입용 추가 오버로드도 있어요. C++11부터 사용할 수 있어요.
출처: cppreference
본문
<complex> 헤더에 정의되어 있고, 시그니처는 다음과 같아요.
template< class T >
T arg( const std::complex<T>& z );
(1)
추가 오버로드 (C++11부터): <complex> 헤더에 정의되어 있어요.
float arg( float f );
double arg( double f );
long double arg( long double f );
(A) (until C++23)
template< class FloatingPoint >
FloatingPoint
arg( FloatingPoint f );
(since C++23)
template< class Integer >
double arg( Integer i );
(B)
-
- 복소수 z의 위상각(라디안)을 계산해요.
- A,B) 모든 정수·부동소수점 타입에 대해 추가 오버로드가 제공되는데, 허수 성분이 0인 복소수처럼 취급돼요.
(C++11부터)
매개변수 (Parameters)
- z — 복소수 값
- f — 부동소수점 값
- i — 정수 값
반환값 (Return value)
-
std::atan2(std::imag(z), std::real(z)). 오류가 없다면 [−π; π] 구간의 z 위상각이에요.
- A) f가 양수 또는 +0이면 0, f가 음수 또는 -0이면 π, 그 외에는 NaN이에요.
- B) i가 음수가 아니면 0, 음수이면 π예요.
참고 (Notes)
추가 오버로드는 정확히 (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))과 같은 효과예요.
예제 (Example)
이 코드를 실행해 봐요.
#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