名前空間
変種
操作

FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN

提供: cppreference.com
< c‎ | numeric‎ | math
 
 
 
一般的な数学関数
関数
基本操作
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
指数関数
(C99)
(C99)
冪関数
三角関数と双曲線関数
誤差関数とガンマ関数
(C99)
(C99)
(C99)
(C99)
最も近い整数
(C99)
(C99)(C99)(C99)
浮動小数点操作関数
(C99)(C99)
(C99)
(C99)
分類
(C99)
(C99)
(C99)
(C99)(C99)
マクロ定数
(C99)
FP_NORMALFP_SUBNORMALFP_ZEROFP_INFINITEFP_NAN
(C99)(C99)(C99)(C99)(C99)
 
ヘッダ <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) であることを表します

[編集]

#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

[編集]参考文献

  • C11 standard (ISO/IEC 9899:2011):
  • 7.12/6 FP_NORMAL, ... (p: 232)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.12/6 FP_NORMAL, ... (p: 213)

[編集]関連項目

指定された浮動小数点値を分類します
(関数マクロ)[edit]
浮動小数点値カテゴリC++リファレンス
close