最終更新日時(UTC):
が更新

履歴 編集

function template
<complex>

std::conj

namespace std {
  template <class T>
  complex<T>
    conj(const complex<T>& x); // (1) C++03
  template <class T>
  constexpr complex<T>
    conj(const complex<T>& x); // (1) C++20

  complex<Promoted>
    conj(Arithmetic x);        // (2) C++11
  constexpr complex<Promoted>
    conj(Arithmetic x);        // (2) C++26
}

概要

共役複素数を得る。conj は conjugate(共役)の略。

  • (1) : complex<T>に対するオーバーロード
  • (2) : 算術型に対する追加のオーバーロード

(2)は、以下のように振る舞う:

  • 実引数の型が浮動小数点数型 T の場合、complex<T> にキャストされているかのように振る舞う
  • そうでなくて、実引数が整数型の場合、complex<double> にキャストされているかのように振る舞う (C++23)

また、これらの追加のオーバーロードが関数テンプレートなのか否か、あるいは、引数が参照型なのか否かなどについては、規格では何も言及されていない。

戻り値

引数 x の共役複素数

#include <iostream>
#include <complex>

int main()
{
  std::complex<double> c(1.0, 2.0);

  std::complex<double> result = std::conj(c);
  std::cout << "conj( " << c << " ) = " << result << std::endl;
}

出力

conj( (1,2) ) = (1,-2)

バージョン

言語

  • C++98(追加のオーバーロードは C++11 から)

処理系

  • Clang: 3.0, 3.1, 3.2, 3.3, 3.4(追加のオーバーロード含む)
  • GCC: 4.3.6, 4.4.7, 4.5.4, 4.6.4, 4.7.3, 4.8.1, 4.8.2, 4.9.0(追加のオーバーロード以外)
  • GCC: 4.3.6, 4.4.7, 4.5.4, 4.6.4, 4.7.3, 4.8.1, 4.8.2, 4.9.0(追加のオーバーロード含む)
  • ICC: ??
  • Visual C++: ??

関連項目

名前 説明
real 複素数の実部を得る。
imag 複素数の虚部を得る。
abs 複素数の絶対値を得る。
arg 複素数の偏角を得る。
norm 複素数体のノルムを得る。
proj リーマン球面への射影を得る。
polar 指定した絶対値と偏角の複素数値を得る。

参照