Skip to content

Latest commit

 

History

History
83 lines (63 loc) · 2.55 KB

isinf.md

File metadata and controls

83 lines (63 loc) · 2.55 KB

isinf

  • cmath[meta header]
  • std[meta namespace]
  • function[meta id-type]
  • cpp11[meta cpp]
namespace std {
  bool isinf(float x);            // (1) C++11からC++20まで
  bool isinf(double x);           // (2) C++11からC++20まで
  bool isinf(long double x);      // (3) C++11からC++20まで

  constexpr bool
    isinf(floating-point-type x); // (4) C++23

  bool
    isinf(Integral x);            // (5) C++11
  constexpr bool
    isinf(Integral x);            // (5) C++23
}
  • Integral[italic]

概要

数値が無限大(infinity)であるか判定する。

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

戻り値

パラメータxが(正もしくは負の)無限大である場合、trueを返す。そうでない場合、falseを返す。

備考

  • C標準ライブラリではisinfは関数マクロとして定義されるが、C++標準ライブラリでは関数として定義される
  • C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された

#include <cassert>
#include <cmath>
#include <limits>

int main()
{
  bool result = std::isinf(std::numeric_limits<float>::infinity());
  assert(result);
}
  • std::isinf[color ff0000]
  • infinity()[link /reference/limits/numeric_limits/infinity.md]

出力

備考

特定の環境では、早期に constexpr 対応されている場合がある:

  • GCC 4.6.1 以上

バージョン

言語

  • C++11

処理系

参照