Namespaces
Variants

std:: arg (std::complex)

From cppreference.net
ヘッダーで定義 <complex>
template < class T >
T           arg ( const std:: complex < T > & z ) ;
(1)
ヘッダーで定義 <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) すべての整数型および浮動小数点型に対して追加のオーバーロードが提供されており、これらは虚数部がゼロの複素数として扱われます。
(C++11以降)

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - HTMLタグ、属性、リンク先は一切変更していません - C++関連の用語(Parameters、Return value、Notes、Example、See also)は原文のまま保持しています - 数値、クラス名、IDなどはすべて元のままです - フォーマットと構造は完全に保持されています

パラメータ

z - 複素数値
f - 浮動小数点値
i - 整数値

戻り値

1) std:: atan2 ( std:: imag ( z ) , std:: real ( z ) ) 。エラーが発生しない場合、これは区間 [−π; π] における z の位相角である。
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と値に適用する
(関数テンプレート)