C++ Reference: Standard C++ Library reference: C Library: cmath: hypot

C++官网参考链接:https://cplusplus.com/reference/cmath/hypot/

函数 
<cmath> <ctgmath>
cbrt
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

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

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

返回值
x^2+y^2之和的平方根。 
如果结果的大小太大,无法用返回类型的值表示,函数可能返回带有适当符号的HUGE_VAL(或HUGE_VALFHUGE_VALL)(在这种情况下,会发生上溢范围错误): 
如果发生上溢范围错误: 
math_errhandling具有MATH_ERRNO集合:全局变量errno设置为ERANGE
math_errhandling具有MATH_ERREXCEPT集合:引发FE_OVERFLOW

用例
/* hypot example */
#include <stdio.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;
}
输出:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值