FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
來自 cppreference.com
定義於標頭檔案 <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
|