名稱空間
變體
操作

FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN

來自 cppreference.com
< c‎ | 數值‎ | 數學
 
 
 
常用數學函式
函式
基本操作
(C99)
(C99)
(C99)
(C99)(C99)(C99)(C23)
最大值/最小值操作
(C99)
(C99)
指數函式
(C23)
(C99)
(C99)
(C23)
(C23)

(C99)
(C99)(C23)
(C23)
(C23)
冪函式
(C99)
(C23)
(C23)

(C99)
(C23)
(C23)
三角函式和雙曲函式
(C23)
(C23)
(C23)
(C23)
(C99)
(C99)
(C99)
最近整數浮點數
(C99)(C99)(C99)
(C99)

(C99)(C99)(C99)
(C23)(C23)(C23)(C23)
浮點數操作
(C99)(C99)
(C99)(C23)
(C99)
窄化操作
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
量子與量子指數
十進位制重新編碼函式
總序和載荷函式
分類
(C99)
(C99)
(C99)
(C23)
誤差函式和伽馬函式
(C99)
(C99)
(C99)
(C99)
型別
宏常量
特殊浮點值
(C99)(C23)
引數和返回值
FP_NORMALFP_SUBNORMALFP_ZEROFP_INFINITEFP_NAN
(C99)(C99)(C99)(C99)(C99)
錯誤處理
快速操作指示符
 
定義於標頭檔案 <math.h>
#define FP_NORMAL    /*實現定義*/
(C99 起)
#define FP_SUBNORMAL /*實現定義*/
(C99 起)
#define FP_ZERO      /*實現定義*/
(C99 起)
#define FP_INFINITE  /*實現定義*/
(C99 起)
#define FP_NAN       /*實現定義*/
(C99 起)

FP_NORMALFP_SUBNORMALFP_ZEROFP_INFINITEFP_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)

[編輯] 參閱

對給定浮點值進行分類
(函式宏) [編輯]
C++ 文件 針對 FP_categories