---
title: hypot
description: "计算实数x^2 + y^2的平方根。"
url: https://www.hikunpeng.com/document/detail/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0183.html
sourcePath: /source/zh/hpchistory/hpckit/develop2400/kunpengaccel_kml_0183.html
indexId: 40d36edafea668ab212c076663ce28f2848b77c4e4dfbb83070c4bb96166faa767
---
# hypot

计算实数x^2 + y^2的平方根。

#### 接口定义

C interface：

float hypotf(float x, float y);

double hypot(double x, double y);

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


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在hypotf中，x是单精度浮点类型。 在hypot中，x是双精度浮点类型。 在hypotl中，x是长双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |
| y | 在hypotf中，y是单精度浮点类型。 在hypot中，y是双精度浮点类型。 在hypotl中，y是长双精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |


#### 返回值

- 返回x^2 + y^2的平方根，x ∈ (-INF, +INF)，y ∈ (-INF, +INF)。
- 输入x为±inf或者y为±inf，返回inf。
- 输入x为nan或者y为nan，返回nan。
- x^2 + y^2开方大于inf，返回inf（Intel在部分情况会返回nan）。


#### 依赖

C: "km.h"


#### 示例

C interface：

```
// typical usage
    float x1 = 3.0, x2 = 0x1.fp127;
    float y1 = 4.0, y2 = -0x1p70;
    // special handling
    float e = INFINITY, f = -INFINITY, g = NAN;
    // print result
    printf("hypotf(3.0, 4.0) = %.15f\n", hypotf(x1, y1));
    printf("hypotf(0x1.fp127, 0x1.fp127) = %.15f\n", hypotf(x2, x2));
    printf("hypotf(-0x1p70, -0x1p70) = %.15f\n", hypotf(y2, y2));
    printf("hypotf(INFINITY, 0) = %.15f\n", hypotf(e, 0.0f));
    printf("hypotf(-INFINITY, 3.0) = %.15f\n", hypotf(f, x1));
    printf("hypotf(NAN, 3.0) = %.15f\n", hypotf(g, x1));
    printf("hypotf(NAN, INFINITY) = %.15f\n", hypotf(g, e));
    /* 
     * hypotf(3.0, 4.0) = 5.000000000000000
     * hypotf(0x1.fp127, 0x1.fp127) = inf
     * hypotf(-0x1p70, -0x1p70) = 1669608653068460621824.000000000000000
     * hypotf(INFINITY, 0) = inf
     * hypotf(-INFINITY, 3.0) = inf
     * hypotf(NAN, 3.0) = nan
     * hypotf(NAN, INFINITY) = inf
     * 
     * */
```
