C++ STL 中的 sinh()函数
sinh()是 C++ STL 中的内置函数,它返回以弧度给定的角度的双曲正弦值。
句法 :
sinh(data_type x)
参数:该函数接受一个强制性参数x ,它指定以弧度为单位的双曲角。参数可以是 double、float 或 long double 数据类型。
返回值:该函数返回参数的双曲正弦值。如果结果的大小太大而无法由返回类型的值表示,则该函数返回inf 。
方案一:
// C++ program to demonstrate the
// sinh() function
#include
using namespace std;
int main()
{
double x = 4.1;
double result = sinh(x);
cout << "sinh(4.1) = " << result << endl;
// x in Degrees
double xDegrees = 90;
x = xDegrees * 3.14159 / 180;
result = sinh(x);
cout << "sinh(90 degrees) = " << result << endl;
return 0;
}
输出:
sinh(4.1) = 30.1619
sinh(90 degrees) = 2.3013
方案二:
// C++ program to demonstrate the
// sinh() function
#include
using namespace std;
int main()
{
int x = -4;
double result = sinh(x);
cout << "sinh(-4) = " << result << endl;
// x in Degrees
double xDegrees = 90;
// convert to radians
x = xDegrees * 3.14159 / 180;
result = sinh(x);
cout << "sinh(90 degrees) = " << result << endl;
return 0;
}
输出:
sinh(-4) = -27.2899
sinh(90 degrees) = 1.1752
错误和异常:当字符串或字符作为参数传递时,该函数没有返回匹配的函数来调用错误。
下面的程序说明了 sinh() 方法的错误和异常:
方案三:
// C++ program to demonstrate the
// sinh() function when a string is passed
#include
using namespace std;
int main()
{
string x = "gfg";
double result;
result = sinh(x);
cout << "sinh(x) = " << result << endl;
return 0;
}
输出:
prog.cpp:14:20: error: no matching function for call to 'sinh(std::__cxx11::string&)'
result = sinh(x);
程序4:
// C++ program to demonstrate the sinh()
// function When argument is too large
#include
using namespace std;
int main()
{
double x = 3000.0;
double result = sinh(x);
cout << "sinh(x) = " << result << endl;
return 0;
}
输出:
sinh(3000.0) = inf