©
This document uses PHP Chinese website manual Release
在头文件<math.h>中定义 | ||
---|---|---|
#define FP_NORMAL / *实现定义* / | (自C99以来) | |
#define FP_SUBNORMAL / *实现定义* / | (自C99以来) | |
#define FP_ZERO / *实现定义* / | (自C99以来) | |
#define FP_INFINITE / *实现定义* / | (自C99以来) | |
#define FP_NAN / *实现定义* / | (自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> 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 ++文档 |