?
This document uses PHP Chinese website manual Release
在頭文件<math.h>中定義 | ||
---|---|---|
#define FP_NORMAL / *實現(xiàn)定義* / | (自C99以來) | |
#define FP_SUBNORMAL / *實現(xiàn)定義* / | (自C99以來) | |
#define FP_ZERO / *實現(xiàn)定義* / | (自C99以來) | |
#define FP_INFINITE / *實現(xiàn)定義* / | (自C99以來) | |
#define FP_NAN / *實現(xiàn)定義* / | (自C99以來) |
FP_NORMAL,F(xiàn)P_SUBNORMAL,F(xiàn)P_ZERO,F(xiàn)P_INFINITE,F(xiàn)P_NAN宏分別表示不同類別的浮點數(shù)。 它們都擴展為整型常量表達式。
常量 | 說明 |
---|---|
FP_NORMAL | 表示該值是正常的,即不是無窮大,低于正常值,非數(shù)值或零 |
FP_SUBNORMAL | 表示該值是低于正常的 |
FP_ZERO | 表示該值為正值或負值為零 |
FP_INFINITE | 表示該值不能由潛在類型表示(正或負無窮) |
FP_NAN | 表示該值不是數(shù)字(NaN) |
#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 Inf0.0/0.0 is NaNDBL_MIN/2 is subnormal-0.0 is zero 1.0 is normal
C11標準(ISO / IEC 9899:2011):
7.12 / 6 FP_NORMAL,...(p:232)
C99標準(ISO / IEC 9899:1999):
7.12 / 6 FP_NORMAL,...(p:213)
fpclassify (C99) | classifies the given floating-point value (function) |
---|
| FP_categories的C ++文檔 |