atanh()是C++ STL中的内置函数,该函数返回以弧度给出的角度的反双曲正切值。
用法:
atanh(data_type x)
参数:该函数接受一个强制性参数x,该参数指定弧度的反双曲角在[-1,1]范围内。该参数可以是double,float或long double数据类型。
返回值:此函数以弧度形式返回参数的反双曲正弦值,具体取决于在参数中传递的参数。下表中给出了不同的返回值:
以下示例程序旨在说明上述方法:
示例1:
// C++ program to illustrate
// the atanh() function
// all return values
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Return value when -1<x<1
int x = 0;
// Function call to calculate atanh(x) value
double result = atanh(x);
cout << "atanh(0) = " << result << " radians\n";
cout << "atanh(0) = " << result * 180 / 3.141592
<< " degrees\n";
// Return value when x=-1
x = -1;
result = atanh(x);
cout << "\natanh(-1) = " << result << " radians\n";
cout << "atanh(-1) = " << result * 180 / 3.141592
<< " degrees\n";
// Return value when x=1
x = 1;
result = atanh(x);
cout << "\natanh(1) = " << result << " radians\n";
cout << "atanh(1) = " << result * 180 / 3.141592
<< " degrees\n";
// Return value when x<-1 or x>1
x = -2;
result = atanh(x);
cout << "\natanh(-2) = " << result << " radians\n";
cout << "atanh(-2) = " << result * 180 / 3.141592
<< " degrees\n";
return 0;
}
输出:
atanh(0) = 0 radians atanh(0) = 0 degrees atanh(-1) = -inf radians atanh(-1) = -inf degrees atanh(1) = inf radians atanh(1) = inf degrees atanh(-2) = -nan radians atanh(-2) = -nan degrees
错误和异常:当传递字符串或任何其他data_type以外的函数时,该函数将返回不匹配的函数错误消息。
示例2:
// C++ program to demonstrate
// the atanh() function
// string passed
#include <bits/stdc++.h>
using namespace std;
int main()
{
string x = "gfg";
// Function call to calculate atanh(x) value
double result = atanh(x);
cout << "atanh(50.0) = " << result << " radians" << endl;
cout << "atanh(50.0) = " << result * 180 / 3.141592
<< " degrees" << endl;
return 0;
}
输出:
prog.cpp:11:25: error: no matching function for call to 'atanh(std::__cxx11::string&)' double result = atanh(x);
相关用法
- C++ complex atanh()用法及代码示例
- C++ fma()用法及代码示例
- C++ div()用法及代码示例
- C++ log()用法及代码示例
- C++ mbsinit()用法及代码示例
- C++ strrchr()用法及代码示例
- C++ bit_and用法及代码示例
- C++ atexit()用法及代码示例
- C++ isunordered()用法及代码示例
- C++ iswalpha()用法及代码示例
- C++ towupper()用法及代码示例
注:本文由纯净天空筛选整理自pawan_asipu大神的英文原创作品 atanh() function in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。