Home C&C++函数库 c++ 语法 程序源码 Linux C库

hypot

函数  <cmath> <ctgmath>

C99 double hypot (double x , double y);
float hypotf (float x , float y);
long double hypotl (long double x, long double y);
C++11 double hypot (double x , double y);
float hypot (float x , float y);
long double hypot (long double x , long double y);
double hypot (Type1 x , Type2 y);     // additional overloads

计算直角三角形的斜边
返回边长为x和y的直角三角形的斜边。
该函数返回x和y平方和的平方根(根据勾股定理),但不会导致中间值的过度溢出或下溢。
C99 头文件<tgmath.h> 提供了该函数的泛型类型宏版本。
C++11 这个头文件(<cmath>) 为其他算术类型(Type1和Type2)的组合提供了额外的重载: 这些重载在计算前将其实参转换为double,除非至少有一个实参是long double类型 (在这种情况下,两个实参都被转换为long double类型)。

☲  参数


x,y
计算斜边的直角三角形的边对应的浮点值。

☉  返回值



(x2+y2)的平方根

如果结果的值太大,不能用返回类型的值表示, 函数可以返回带有适当符号的HUGE_VAL (或HUGE_VALFHUGE_VALL) (在这种情况下,会发生溢出范围错误)
如果发生溢出范围错误:
-并且math_errhandling设置了MATH_ERRNO:全局变量errno设置为ERANGE。
-并且math_errhandling设置了MATH_ERREXCEPT:触发FE_OVERFLOW

☣  示例



/* hypot example */
#include <tdio.h>      /* printf */
#include <math.h>       /* hypot */

int main ()
{
  double leg_x, leg_y, result;
  leg_x = 3;
  leg_y = 4;
  result = hypot (leg_x, leg_y);
  printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
  return 0;
}

输出:
3.000000, 4.000000 and 5.000000 form a right-angled triangle.

🍄  另请参阅



sqrt 计算平方根(function )
pow 幂(function )

联系我们 免责声明 关于CandCplus 网站地图