nan, nanf, nanl, nand32, nand64, nand128
來自 cppreference.com
定義於標頭檔案 <math.h> |
||
float nanf( const char* arg ); |
(1) | (C99 起) |
double nan( const char* arg ); |
(2) | (C99 起) |
long double nanl( const char* arg ); |
(3) | (C99 起) |
_Decimal32 nand32( const char* arg ); |
(4) | (自 C23 起) |
_Decimal64 nand64( const char* arg ); |
(5) | (自 C23 起) |
_Decimal128 nand128( const char* arg ); |
(6) | (自 C23 起) |
將實現定義的字串 arg
轉換為相應的靜默 NaN 值,如同呼叫適當的解析函式 strtoX
,如下所示:
- 呼叫 nan("n-char-sequence"),其中 n-char-sequence 是數字、拉丁字母和下劃線的序列,等同於呼叫 /*strtoX*/("NAN(n-char-sequence)", (char**)NULL);。
- 呼叫 nan("") 等同於呼叫 /*strtoX*/("NAN()", (char**)NULL);。
- 呼叫 nan("string"),其中 string 既不是 n-char-sequence 也不是空字串,等同於呼叫 /*strtoX*/("NAN", (char**)NULL);。
1) 解析函式是 strtof。
2) 解析函式是 strtod。
3) 解析函式是 strtold。
4) 解析函式是 strtod32。
5) 解析函式是 strtod64。
6) 解析函式是 strtod128。
僅當實現預定義了 |
(自 C23 起) |
目錄 |
[編輯] 引數
arg | - | 窄字元字串,用於標識 NaN 的內容 |
[編輯] 返回值
對應於標識字串 arg
的靜默 NaN 值,如果實現不支援靜默 NaN,則返回零。
如果實現支援 IEEE 浮點算術(IEC 60559),它也支援靜默 NaN。
[編輯] 錯誤處理
此函式不受 math_errhandling 中指定的任何錯誤條件的影響。
[編輯] 示例
執行此程式碼
#include <stdio.h> #include <math.h> #include <stdint.h> #include <inttypes.h> #include <string.h> int main(void) { double f1 = nan("1"); uint64_t f1n; memcpy(&f1n, &f1, sizeof f1); printf("nan(\"1\") = %f (%" PRIx64 ")\n", f1, f1n); double f2 = nan("2"); uint64_t f2n; memcpy(&f2n, &f2, sizeof f2); printf("nan(\"2\") = %f (%" PRIx64 ")\n", f2, f2n); double f3 = nan("0xF"); uint64_t f3n; memcpy(&f3n, &f3, sizeof f3); printf("nan(\"0xF\") = %f (%" PRIx64 ")\n", f3, f3n); }
可能的輸出
nan("1") = nan (7ff8000000000001) nan("2") = nan (7ff8000000000002) nan("0xF") = nan (7ff800000000000f)
[編輯] 參考
- C17 標準 (ISO/IEC 9899:2018)
- 7.12.11.2 nan 函式 (p: 186-187)
- F.10.8.2 nan 函式 (p: 386)
- C11 標準 (ISO/IEC 9899:2011)
- 7.12.11.2 nan 函式 (p: 256)
- F.10.8.2 nan 函式 (p: 529)
- C99 標準 (ISO/IEC 9899:1999)
- 7.12.11.2 nan 函式 (p: 237)
- F.9.8.2 fabs 函式 (p: 465)
[編輯] 另請參閱
(C99) |
檢查給定數字是否為 NaN (函式宏) |
(C99) |
評估為 float 型別的靜默 NaN(非數字) (宏常量) |
C++ 文件,關於 nanf, nan, nanl
|