当前位置: C语言 -- 标准库 -- <math.h> -- hypot

hypot函数


概要:
#include <math.h>
double hypot(double x, double y);

描述:

该函数计算表达式x2+y2的值,在计算的中间阶段没有过度的溢出或者下溢。

该函数可能会发生范围错误(range error)


参数:
double x

参数为一个double类型的浮点数。

double y

参数为一个double类型的浮点数。


返回值:

函数返回x2+y2的值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数hypot范例*/

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

int main(void)
{
    double x = 3.0, y = 4.0;
    double z;

    z = hypot(x, y);
    printf("The square root of the sum of the squares of %.6f and %.6f is %.6f.\n", x, y, z);

    return 0;
}

输出:

The square root of the sum of the squares of 3.000000 and 4.000000 is 5.000000.


相关内容:
hypotf float类型的返回x2+y2的函数。
hypotl long double类型的返回x2+y2的函数。