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

copysignd32函数


概要:
#include <math.h>
#ifdef __STDC_IEC_60559_DFP__
    _Decimal32 copysignd32(_Decimal32 x, _Decimal32 y);
#endif 

描述:

该函数生成一个值,该值具有参数x的绝对值和参数y的符号。

如果参数x或者参数y是无符号值,结果的符号(如果存在。)将由实现定义。

对于表示有符号0、但在算术运算中不一致地处理负0的实现,该函数应将0的符号视为正号。


参数:
_Decimal32 x

参数为_Decimal32类型的浮点数。

_Decimal32 y

参数为_Decimal32类型的浮点数。


返回值:

函数返回绝对值与参数x相同、符号与参数y相同的值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数copysignd32范例*/

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

int main(void)
{
    #if __STDC_VERSION_MATH_H__ >= 202311L && defined(__STDC_IEC_60559_DFP__)
        printf("copysignd32(10.0df, -5.0df) = %.2Hf\n", copysignd32(10.0df,-5.0df));
    #else
        puts("The implementation does not support copysignd32 function.");
    #endif

    return 0;
}

可能输出:

copysignd32(10.0df, -5.0df) = -10.00

(注:编译时实现还未支持copysignd32函数。)


相关内容:
copysign double类型的复制符号函数。
copysignf float类型的复制符号函数。
copysignl long double类型的复制符号函数。
copysignd64 _Decimal64类型的复制符号函数。
copysignd128 _Decimal128类型的复制符号函数。


主要参考资料:

1、ISO/IEC 9899:2024