#C 语言标准库函数 copysignd32
#include <math.h>
_Decimal32 copysignd32(_Decimal32 x, _Decimal32 y);
说明
把第二个操作数的符号复制到第一个操作数的数值幅度上。
取符号时可辨别 IEC 60559 实现的正零和负零。
自 C23 起提供。需要实现定义 __STDC_IEC_60559_DFP__ 并提供对应的十进制浮点接口。
参数
x- 提供幅度的值。y- 提供符号的值。
返回值
- 返回幅度取自 x、符号取自 y 的浮点值。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <math.h>
#include <stdio.h>
int main(void)
{
_Decimal32 computed = copysignd32(3.0df, -1.0df);
printf("%Lg\n", (long double)computed);
return !(computed == -3.0df);
}
运行结果。
-3
#相关接口
- 接口变体 copysign、copysignf、copysignl、copysignd64、copysignd128
- 类型通用分派 copysign(类型通用宏)
- 相关操作 fabsd32、signbit