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 x);
参数
参数名 |
类型 |
描述 |
输入/输出 |
|---|---|---|---|
x |
|
表示输入数据的浮点值。 |
输入 |
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
*
* */
父主题: 指数和对数函数