fpclassify
提供: cppreference.com
ヘッダ <math.h> で定義
|
||
#define fpclassify(arg) /* implementation defined */ |
(C99以上) | |
浮動小数点値 arg
をゼロ、非正規化数、正規化数、無限大、NaN または処理系定義のカテゴリに分類します。 このマクロは整数値を返します。
FLT_EVAL_METHOD は無視されます。 引数がその型よりも広い範囲や高い精度で評価されたとしても、まずその意味論上の型に変換され、それを元に分類されます。 正規化数の long double 値は double や float に変換すると非正規化数になるかもしれません。
目次 |
[編集] 引数
arg | - | 浮動小数点値 |
[編集] 戻り値
arg
のカテゴリを表す FP_INFINITE, FP_NAN, FP_NORMAL, FP_SUBNORMAL, FP_ZERO または処理系定義の定数のいずれか。
[編集] 例
Run this code
#include <stdio.h> #include <math.h> #include <float.h> const char *show_classification(double x) { switch(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(void) { printf("1.0/0.0 is %s\n", show_classification(1/0.0)); printf("0.0/0.0 is %s\n", show_classification(0.0/0.0)); printf("DBL_MIN/2 is %s\n", show_classification(DBL_MIN/2)); printf("-0.0 is %s\n", show_classification(-0.0)); printf("1.0 is %s\n", show_classification(1.0)); }
出力:
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
[編集] 参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.12.3.1 The fpclassify macro (p: 235)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.3.1 The fpclassify macro (p: 216)
[編集] 関連項目
(C99) |
指定された値が有限値かどうか調べます (関数マクロ) |
(C99) |
指定された値が無限大かどうか調べます (関数マクロ) |
(C99) |
指定された値が NaN かどうか調べます (関数マクロ) |
(C99) |
指定された数値が正規化数かどうか調べます (関数マクロ) |
fpclassify の C++リファレンス
|