FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
来自 cppreference.cn
定义于头文件 <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 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, ... (p: 169-170)
- C11 标准 (ISO/IEC 9899:2011)
- 7.12/6 FP_NORMAL, ... (p: 232)
- C99 标准 (ISO/IEC 9899:1999)
- 7.12/6 FP_NORMAL, ... (p: 213)
[编辑] 参阅
(C99) |
对给定浮点值进行分类 (函数宏) |
C++ 文档 针对 FP_categories
|