📜  C++ STL中的acosh()函数

📅  最后修改于: 2021-05-30 08:18:24             🧑  作者: Mango

acosh()是C++ STL中的内置函数,它返回以弧度给出的角度的反双曲余弦值。

句法:

acosh(data_type x)

参数:该函数接受一个强制性参数x,该参数指定弧度中的反双曲角应大于或等于1。如果参数小于1,则返回-nan。该参数可以是double,float或long double数据类型。

返回值: acosh()函数以弧度返回参数的反双曲正弦值,范围为[0,inf]。

下面的程序说明了上述方法:

程序1:

// C++ program to demonstrate
// the acosh() function
#include 
using namespace std;
  
int main()
{
    double x = 50.0;
  
    // Function call to calculate acosh(x) value
    double result = acosh(x);
  
    cout << "acosh(50.0) = " << result << " radians" << endl;
    cout << "acosh(50.0) = " << result * 180 / 3.141592
         << " degrees" << endl;
    return 0;
}
输出:
acosh(50.0) = 4.60507 radians
acosh(50.0) = 263.851 degrees

程式2:

// C++ program to demonstrate
// the acosh() function
#include 
using namespace std;
  
int main()
{
    int x = 40.0;
  
    // Function call to calculate acosh(x) value
    double result = acosh(x);
  
    cout << "acosh(40.0) = " << result << " radians" << endl;
    cout << "acosh(40.0) = " << result * 180 / 3.141592
         << " degrees" << endl;
    return 0;
}
输出:
acosh(40.0) = 4.38187 radians
acosh(40.0) = 251.063 degrees

错误和异常:当将字符串或字符作为参数传递时,该函数返回任何匹配函数来调用错误。

程序3:

// C++ program to demonstrate
// the acosh() function
#include 
using namespace std;
  
int main()
{
    string x = "gfg";
  
    // Function call to calculate acosh(x) value
    double result = acosh(x);
  
    cout << "acosh(50.0) = " << result << " radians" << endl;
    cout << "acosh(50.0) = " << result * 180 / 3.141592
         << " degrees" << endl;
    return 0;
}

输出:

prog.cpp:11:25: error: no matching function for call to 'acosh(std::__cxx11::string&)'
  double result = acosh(x);

计划4:

// C++ program to demonstrate
// the acosh() function
// value less than 1
#include 
using namespace std;
  
int main()
{
    double x = -50.0;
  
    // Function call to calculate acosh(x) value
    double result = acosh(x);
  
    cout << "acosh(-50.0) = " << result << " radians" << endl;
    cout << "acosh(-50.0) = " << result * 180 / 3.141592
         << " degrees" << endl;
    return 0;
}
输出:
acosh(-50.0) = -nan radians
acosh(-50.0) = -nan degrees
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”