nanl函数
概要:
#include <math.h>
long double nanl(const char *tagp);
描述:
该函数根据以下规则转换参数tagp指向的字符串:
调用函数nanl("n-char-sequence")等价于调用函数strtold("NAN(n-char-sequence)", (char**)NULL);调用函数nanl("")等价于调用函数strtold("NAN()", (char**)NULL)。
如果参数tagp未指向n-char-sequence序列或者空字符串,调用该函数等价于调用函数strtold("NAN", (char**)NULL)。
参数:
const char *tagp
参数为一个指向n-char-sequence序列或者空字符串的指针。
返回值:
函数返回一个安静非数值(如果可用),其内容通过参数tagp确定。
如果实现不支持安静非数值,函数返回0。
范例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
/*函数nanl范例*/
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
void funcNan(const char *tagp)
{
long double a;
uint96_t b;
a = nanl(tagp);
memcpy(&b,&a,sizeof(long double));
printf("nan(\"%4s\"):%"PRIx96"\n", tagp, b);
}
int main(void)
{
funcNan("64");
funcNan("064");
funcNan("0x64");
return 0;
}
|
输出:
nan(" 64"):
nan(" 064"):
nan("0x64"):
根据IEEE754-2008标准,7fc00040、7fc00034、7fc00064表示的均为非数。详细解释见浮点数的数值范围。
相关内容:
| nan |
double类型的生成安静非数值的函数。 |
| nanf |
float类型的生成安静非数值的函数。 |