📅  最后修改于: 2020-09-25 07:42:53             🧑  作者: Mango
double hypot(double x, double y);
float hypot(float x, float y);
long double hypot(long double x, long double y);
Promoted pow(Type1 x, Type2 y);
double hypot(double x, double y, double x); // (since C++17)
float hypot(float x, float y, float z); // (since C++17)
long double hypot(long double x, long double y, long double z); // (since C++17)
Promoted pow(Type1 x, Type2 y, Type2 y); // (since C++17)
从C++ 11开始,如果传递给hypot()的任何参数为long double
,则返回的Promoted
类型为long double
。如果不是,则返回类型Promoted
为double
。
h = √(x2+y2
在数学上相当于
h = hypot(x, y);
在C++编程中。
如果传递了三个参数:
h = √(x2+y2+z2))
在数学上相当于
h = hypot(x, y);
在C++编程中。
此函数在
hytpot()可以使用2或3个整数或浮点类型的参数。
hypot()返回:
#include
#include
using namespace std;
int main()
{
double x = 2.1, y = 3.1, result;
result = hypot(x, y);
cout << "hypot(x, y) = " << result << endl;
long double yLD, resultLD;
x = 3.52;
yLD = 5.232342323;
// hypot() returns long double in this case
resultLD = hypot(x, yLD);
cout << "hypot(x, yLD) = " << resultLD;
return 0;
}
运行该程序时,输出为:
hypot(x, y) = 3.74433
hypot(x, yLD) = 6.30617
#include
#include
using namespace std;
int main()
{
double x = 2.1, y = 3.1, z = 23.3, result;
result = hypot(x, y, z);
cout << "hypot(x, y, z) = " << result << endl;
return 0;
}
注意:该程序仅在支持C++ 17的新编译器中运行。