?
Ce document utilise Manuel du site Web PHP chinois Libérer
在頭文件<math.h>中定義 | ||
---|---|---|
float nanf( const char* arg ); | (since C99) | |
double nan( const char* arg ); | (since C99) | |
long double nanl( const char* arg ); | (since C99) |
實(shí)現(xiàn)定義字符串轉(zhuǎn)換arg
成相應(yīng)的靜態(tài)NaN值,則通過(guò)調(diào)用strtof
,strtod
或者strtold
,分別說(shuō)明如下:
通話(huà)nan("string")
等同于通話(huà)strtod("NAN(string)", (char**)NULL);
。
通話(huà)nan("")
等同于通話(huà)strtod("NAN()", (char**)NULL);
。
通話(huà)nan(NULL)
等同于通話(huà)strtod("NAN", (char**)NULL);
。
arg | - | 窄字符串標(biāo)識(shí)NaN的內(nèi)容 |
---|
安靜的NaN值與標(biāo)識(shí)字符串相對(duì)應(yīng),arg
或者如果實(shí)現(xiàn)不支持安靜的NaN,則為零。
#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)