FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cmath> で定義
|
||
#define FP_NORMAL /*implementation defined*/ |
(C++11以上) | |
#define FP_SUBNORMAL /*implementation defined*/ |
(C++11以上) | |
#define FP_ZERO /*implementation defined*/ |
(C++11以上) | |
#define FP_INFINITE /*implementation defined*/ |
(C++11以上) | |
#define FP_NAN /*implementation defined*/ |
(C++11以上) | |
FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN マクロはそれぞれ浮動小数点数の異なるカテゴリを表します。 これらはすべて整数定数式に展開されます。
| 定数 | 説明 |
FP_NORMAL
|
値が正規化数、すなわち無限大でも非正規化数でも非数でもゼロでもないことを表します |
FP_SUBNORMAL
|
値が非正規化数であることを表します |
FP_ZERO
|
値が正または負のゼロであることを表します |
FP_INFINITE
|
値がその型で表現できない (正または負の無限大) ことを表します |
FP_NAN
|
値が非数 (NaN) であることを表します |
例
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言語リファレンス
|