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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。