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

履歴 編集

function
<cmath>

std::erfc(C++11)

namespace std {
  float erfc(float x);              // (1) C++11からC++20まで
  double erfc(double x);            // (2) C++11からC++20まで
  long double erfc(long double x);  // (3) C++11からC++20まで

  floating-point-type
    erfc(floating-point-type x);    // (4) C++23

  double erfc(Integral x);          // (5) C++11

  float erfcf(float x);             // (6) C++17
  long double erfcl(long double x); // (7) C++17
}

概要

算術型の相補誤差関数 (complementary error function) を求める。

  • (1) : floatに対するオーバーロード
  • (2) : doubleに対するオーバーロード
  • (3) : long doubleに対するオーバーロード
  • (4) : 浮動小数点数型に対するオーバーロード
  • (5) : 整数型に対するオーバーロード (doubleにキャストして計算される)
  • (6) : float型規定
  • (7) : long double型規定

戻り値

引数 x の相補誤差関数を返す。

x が大き過ぎる場合はアンダーフローエラーとなる。

備考

  • $$ f(x) = \mathrm{erfc}~x \equiv 1 - \mathrm{erf}~x \equiv \frac{2}{\sqrt{\pi}} \int_x^\infty e^{-t^2} dt $$
  • C++11 以降では、処理系が IEC 60559 に準拠している場合(std::numeric_limits<T>::is_iec559() != false)、以下の規定が追加される。
    • x = -∞ の場合、戻り値は 2 となる。
    • x = +∞ の場合、戻り値は +0 となる。
  • C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された

#include <cmath>
#include <iostream>
#include <limits>

int main() {
  std::cout << std::fixed;
  std::cout << "erfc(-∞) = " << std::erfc(-std::numeric_limits<double>::infinity()) << std::endl;
  std::cout << "erfc(0)  = " << std::erfc(0.0) << std::endl;
  std::cout << "erfc(1)  = " << std::erfc(1.0) << std::endl;
  std::cout << "erfc(+∞) = " << std::erfc(std::numeric_limits<double>::infinity()) << std::endl;
}

出力例

erfc(-∞) = 2.000000
erfc(0)  = 1.000000
erfc(1)  = 0.157299
erfc(+∞) = 0.000000

バージョン

言語

  • C++11

処理系

備考

特定の環境で constexpr 指定されている場合がある。(独自拡張)

  • GCC 4.6.1 以上

参照