当前位置: C语言 -- 标准库 -- <math.h> -- nand128

nand128函数


概要:
#include <math.h>
#ifdef __STDC_IEC_60559_DFP__
    _Decimal128 nand128(const char *tagp);
#endif 

描述:

该函数根据以下规则转换参数tagp指向的字符串:

调用函数nand128("d-char-sequence")等价于调用函数strtod128("NAN(d-char-sequence)", nullptr);调用函数nand128("")等价于调用函数strtod128("NAN()", nullptr)。

如果参数tagp未指向d-char-sequence序列或者空字符串,调用该函数等价于调用函数strtod128("NAN", nullptr)。


参数:
const char *tagp

参数为指向d-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 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
/*函数nand128范例*/

#include <math.h>
#include <stdio.h>
#include <string.h>

void funcNan(const char *tagp)
{
    #if __STDC_VERSION_MATH_H__ >= 202311L && defined(__STDC_IEC_60559_DFP__)
        _Decimal128 a;
        size_t size = sizeof(_Decimal128);
        unsigned char arr[size];
    
        a = nand128(tagp);
        memcpy(arr,&a,size);
    
        printf("nand128(\"%s\"): ", tagp);
        for(size_t i=0; i<size; i++)
        {
            printf("%02x", arr[size-1-i]);
        }
    
        printf("\n");
    #else
        puts("The implementation does not support nand128 function.");
    #endif
}

int main(void)
{
    funcNan("");
    funcNan("1");

    return 0;
}


输出:
The implementation does not support nand128 function.
The implementation does not support nand128 function.

(注:编译时实现还未支持十进制浮点类型。)


相关内容:
nan double类型的生成安静非数值的函数。
nanl long double类型的生成安静非数值的函数。
nanf float类型的生成安静非数值的函数。
nand32 _Decimal32类型的生成安静非数值的函数。
nand64 _Decimal64类型的生成安静非数值的函数。


主要参考资料:

1、ISO/IEC 9899:2024