?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
在頭文件<math.h>中定義 | ||
---|---|---|
#define fpclassify(arg)/ *實(shí)現(xiàn)定義* / | (自C99以來) |
將浮點(diǎn)值arg分類為以下類別:零,低于正常,正常,無限,NAN或?qū)崿F(xiàn)定義的類別。 該宏返回一個(gè)整數(shù)值。
FLT_EVAL_METHOD被忽略:即使參數(shù)的計(jì)算范圍和精度超過其類型,它首先會(huì)轉(zhuǎn)換為其語(yǔ)義類型,并且分類基于此:當(dāng)轉(zhuǎn)換為double和zero時(shí),正常的long double值可能會(huì)變?yōu)榈陀谡V?當(dāng)轉(zhuǎn)換為浮動(dòng)值。
arg | - | floating point value |
---|
FP_INFINITE,F(xiàn)P_NAN,F(xiàn)P_NORMAL,F(xiàn)P_SUBNORMAL,F(xiàn)P_ZERO或?qū)崿F(xiàn)定義類型之一,指定arg的類別。
#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 zero1.0 is normal
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.12.3.1 fpclassify宏(p:235)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.12.3.1 fpclassify宏(p:216)
isfinite(C99) | 檢查給定的數(shù)字是否具有有限的值(函數(shù)) |
---|---|
isinf(C99) | 檢查給定的數(shù)字是否是無限的(功能) |
isnan (C99) | 檢查給定的號(hào)碼是否為NaN(功能) |
isnormal (C99) | 檢查給定的數(shù)字是否正常(功能) |
| fpclassify 的C ++文檔|