#C 语言标准库函数 hypotd128
#include <math.h>
_Decimal128 hypotd128(_Decimal128 x, _Decimal128 y);
说明
计算两个分量的平方和再开平方。实现避免中间平方引起的不必要的上溢或下溢。
结果超出类型可表示的范围时可能报告范围错误。数学错误的报告方式由 math_errhandling 指示。
自 C23 起提供。需要实现定义 __STDC_IEC_60559_DFP__ 并提供对应的十进制浮点接口。
参数
x- 第一个直角分量。y- 第二个直角分量。
返回值
- 返回欧氏长度。
#示例
使用 GCC 时,在链接命令末尾添加 -lm。
#include <math.h>
#include <stdio.h>
int main(void)
{
_Decimal128 computed = hypotd128(3.0dl, 4.0dl);
printf("%Lg\n", (long double)computed);
return !(computed == 5.0dl);
}
运行结果。
5