当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ acosh()用法及代码示例


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 <bits/stdc++.h> 
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 <bits/stdc++.h> 
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 <bits/stdc++.h> 
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 <bits/stdc++.h> 
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


相关用法


注:本文由纯净天空筛选整理自pawan_asipu大神的英文原创作品 acosh() function in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。