std::fpclassify
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cmath> で定義
|
||
int fpclassify( float arg ); |
(1) | (C++11以上) |
int fpclassify( double arg ); |
(2) | (C++11以上) |
int fpclassify( long double arg ); |
(3) | (C++11以上) |
int fpclassify( 整数型 arg ); |
(4) | (C++11以上) |
1-3) 浮動小数点値
arg をゼロ、非正規化数、正規化数、無限大、NaN または処理系定義のカテゴリに分類します。引数
| arg | - | 浮動小数点値 |
戻り値
arg のカテゴリを表す FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO または処理系定義の定数のいずれか。
例
Run this code
#include <iostream>
#include <cmath>
#include <cfloat>
const char* show_classification(double x) {
switch(std::fpclassify(x)) {
case FP_INFINITE: return "Inf";
case FP_NAN: return "NaN";
case FP_NORMAL: return "normal";
case FP_SUBNORMAL: return "subnormal";
case FP_ZERO: return "zero";
default: return "unknown";
}
}
int main()
{
std::cout << "1.0/0.0 is " << show_classification(1/0.0) << '\n'
<< "0.0/0.0 is " << show_classification(0.0/0.0) << '\n'
<< "DBL_MIN/2 is " << show_classification(DBL_MIN/2) << '\n'
<< "-0.0 is " << show_classification(-0.0) << '\n'
<< "1.0 is " << show_classification(1.0) << '\n';
}
出力:
1.0/0.0 is Inf
0.0/0.0 is NaN
DBL_MIN/2 is subnormal
-0.0 is zero
1.0 is normal
関連項目
(C++11) |
指定された数値が有限値を持つかどうか調べます (関数) |
(C++11) |
指定された数値が無限大かどうか調べます (関数) |
(C++11) |
指定された数値が NaN かどうか調べます (関数) |
(C++11) |
指定された数値が正規化数かどうか調べます (関数) |
| すべての基本数値型の性質を問い合わせるインタフェースを提供します (クラステンプレート) | |
fpclassify の C言語リファレンス
| |