Namespaces
Variants

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 ) ;

long double arg ( long double f ) ;
(C++23 이전)
template < class FloatingPoint >

FloatingPoint

arg ( FloatingPoint f ) ;
(C++23부터)
template < class Integer >
double arg ( Integer i ) ;
(B)
1) 복소수 z 의 위상각(라디안 단위)을 계산합니다.
A,B) 모든 정수 및 부동소수점 타입에 대해 추가 오버로드가 제공되며, 이들은 허수부가 0인 복소수로 처리됩니다.
(since C++11)

목차

매개변수

z - 복소수 값
f - 부동소수점 값
i - 정수 값

반환값

1) std:: atan2 ( std:: imag ( z ) , std:: real ( z ) ) . 오류가 발생하지 않으면, 이는 z 의 위상각으로 구간 [−π; π] 내에 있습니다.
A) f 가 양수 또는 +0이면 0, π f 가 음수 또는 -0이면 π, 그렇지 않으면 NaN.
B) i가 음수가 아닌 경우 0, 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

참고 항목

복소수의 크기를 반환합니다
(function template)
크기와 위상각으로부터 복소수를 생성합니다
(function template)
(C++11) (C++11)
사분면을 결정하기 위해 부호를 사용하는 아크 탄젠트
(function)
함수 std::atan2 를 valarray와 값에 적용합니다
(function template)