FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
提供: cppreference.com
ヘッダ <math.h> で定義 | ||
#define FP_NORMAL /*implementation defined*/ | (C99以上) | |
#define FP_SUBNORMAL /*implementation defined*/ | (C99以上) | |
#define FP_ZERO /*implementation defined*/ | (C99以上) | |
#define FP_INFINITE /*implementation defined*/ | (C99以上) | |
#define FP_NAN /*implementation defined*/ | (C99以上) | |
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 <stdio.h>#include <math.h>#include <float.h> constchar*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