isnan
, _isnan
, _isnanf
測試浮點值是否為 NaN(「不是數位」)。
語法
int isnan(
/* floating-point */ x
); /* C-only macro */
int _isnan(
double x
);
int _isnanf(
float x
); /* x64 only */
template <class T>
bool isnan(
T x
) throw(); /* C++ only */
參數
x
要測試的浮點值。
傳回值
在 C 中 isnan
,如果引數 x
為 NaN,宏和 和 _isnan
_isnanf
函式會傳回非零值,否則會傳回 0。
在 C++ 中 isnan
,如果引數 x
是 NaN,則樣板函式會 true
傳回 ,否則會傳 false
回 。
備註
因為 NaN 值不會與本身或任何其他 NaN 值相比較,因此若要偵測其中一個值,您必須使用下列其中一個函式或宏。 當指定的類型無法以 IEEE-754 浮點格式表示浮點運算的結果時,會產生 NaN。 如需 NaN 如何代表輸出的資訊,請參閱 printf
。
當編譯為 C++ 時, isnan
不會定義宏,而是 isnan
定義範本函式。 其行為方式與宏相同,但會傳回 型 bool
別的值,而不是整數。
和 _isnanf
函 _isnan
式是 Microsoft 特有的。 _isnanf
函式只適用於 x64 編譯時。
需求
常式 | 必要的標頭 (C) | 必要的標頭 (C++) |
---|---|---|
isnan , _isnanf |
<math.h> | <math.h > 或 < cmath> |
_isnan |
<float.h> | <float.h > 或 < cfloat> |
如需相容性詳細資訊,請參閱相容性。
另請參閱
數學和浮點支援
fpclassify
_fpclass
, _fpclassf
isfinite
, _finite
, _finitef
isinf
isnormal
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應