FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
From cppreference.net
Common mathematical functions
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<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> 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
参考文献
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.12/6 FP_NORMAL, ... (页码: 169-170)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.12/6 FP_NORMAL, ... (页码: 232)
- C99标准(ISO/IEC 9899:1999):
-
- 7.12/6 FP_NORMAL, ...(页码:213)
参见
|
(C99)
|
对给定的浮点数值进行分类
(函数宏) |
|
C++ 文档
关于
FP_categories
|
|