名前空間
変種
操作

std::arg(std::complex)

From cppreference.com
< cpp‎ | numeric‎ | complex
 
 
 
 
ヘッダ <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以降)

目次

[編集] パラメータ

z - complex value
f - floating-point value
i - 整数値

[編集] 戻り値

1) std::atan2(std::imag(z), std::real(z))。エラーが発生しない場合、これは区間 [−π; π] における z の位相角です。
A) f が正または +0 の場合は 0、 f が負または -0 の場合は π、それ以外の場合は NaN。
B) i が非負の場合は 0、負の場合は π

[編集] 注意

追加のオーバーロードは、(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)
符号を用いて象限を決定する逆正接
(関数) [編集]
valarrayと値に関数std::atan2を適用する
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)