约 1153 字

约 6 分钟

#C 语言标准库函数 hypotl

#include <math.h>

long double hypotl(long double x, long double y);

说明

计算两个分量的平方和再开平方。实现避免中间平方引起的不必要的上溢或下溢。

结果超出类型可表示的范围时可能报告范围错误。数学错误的报告方式由 math_errhandling 指示。

自 C99 起提供。

参数

  • x - 第一个直角分量。
  • y - 第二个直角分量。

返回值

  • 返回欧氏长度。

#示例

使用 GCC 时,在链接命令末尾添加 -lm。

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

int main(void)
{
    long double computed = hypotl(3.0L, 4.0L);
    printf("%Lg\n", (long double)computed);
    return !(computed == 5.0);
}

运行结果。

5

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28