std::complex

なんとなくまとめてみました。自分用ですが。

  • T = 実部と虚部の型
  • C = complex

と思ってください。

Constructor

  complex(T r = 0, T i = 0);

Public methods

  T real() const;
  T imag() const;

  foreach OP in += -= *= /=
    C& operator OP (const C&);
    C& operator OP (T);

Operators

  foreach OP in + - * / == !=
    C operator OP (const C&, const C&);
    C operator OP (const C&, T);
    C operator OP (T, const C&);

  // 前置
  C operator + (const C&);
  C operator - (const C&);

  // 入出力
  istream& operator >> (istream&, const C&);
  ostream& operator << (ostream&, const C&);

比較関数はありません。
複素数のsetやmapが欲しいときは自分で定義する必要あり。

Related functions

  T real(const C&);   // z.real() と同じ
  T imag(const C&);   // z.imag() と同じ
  T abs(const C&);    // 絶対値 hypot(x, y) = sqrt(x*x + y*y)
  T arg(const C&);    // 偏角 atan2(y, x)
  C& polar(T r, T t); // 極座標 (r*cos(t), r*sin(t))
  C& conj(const C&);  // 共役複素数 C(x, -y)
  T norm(const C&);   // ノルム (x*x + y*y)

  foreach f in exp, log, log10, sqrt, cos, cosh, sin, sinh, tan, tanh
    C& f(const C&);

  C& pow(const C&, constC&);
  C& pow(const C&, T);
  C& pow(const C&, int);
  C& pow(T, const C&);

メモ

in math.h

  • atan(double a) returns (-π/2, π/2)
  • atan2(double y, double x) returns (-π, π)