atanh() function in C++ STL

C++ STL Function : atanh()

The atanh() function uses a mathematical formula to calculate the inverse hyperbolic tangent of a number. This formula involves the use of exponential functions and involves the ratio of the sides of a right triangle in a hyperbolic coordinate system.In this section, we will discuss about library function atanh() in STL which is used in C++.The Standard Template Library(STL) is a set of complete data structures and functions which can be used in C++. 

 

atanh() function in c++ stl

Library Function atanh() in C++

In C++ programming language, the atanh function is included in standard template library.

The range of input argument which is passed to floor function is not limited here as it can be any value such as float or long double also.

Declaration of atanh function

atanh(data_type x)

Parameters of atanh function

The atanh function accepts a single input argument  which is the hyperbolic angle and can be a double/float or long double value.

Parameter           Description
Hyperbolic angle          This value of the parameter can be of double / float /int or long double type.

Return value of atanh function

The atanh function returns the inverse hyperbolic tangent value of the argument passed.

Parameter      Return Value
-1 < x < 1     It returns a finite value.
x > 1 or x < -1     It returns NaN ( Not a number).
x = -1     It returns (-inf).
x = 1     It returns (+inf).

Implementation of STL Function atanh() in C++

Example 1:

The following code shows the use of atanh function.

Run

#include<bits/stdc++.h> 
using namespace std;  
int main()
{
    int x = 0;
    double result = atanh(x);
    cout << "atanh(0) = " << result << " radians\n";
    cout << "atanh(0) = " << result * 180 / 3.141592 << " degrees\n";
    
x = -1;
    result = atanh(x);
    cout << "\natanh(-1) = " << result << " radians\n";
    cout << "atanh(-1) = " << result * 180 / 3.141592 << " degrees\n";
 
    x = 1;
    result = atanh(x);
    cout << "\natanh(1) = " << result << " radians\n";
    cout << "atanh(1) = " << result * 180 / 3.141592 << " degrees\n";
 
    x = -2;
    result = atanh(x);
    cout << "\natanh(-2) = " << result << " radians\n";
    cout << "atanh(-2) = " << result * 180 / 3.141592 << " degrees\n";
 
    return 0;
}

Output:

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

Example 2:

Run

#include<bits/stdc++.h> 
using namespace std;
int main()
{
    string x = "abc";
    double result = atanh(x);
    cout << "atanh(50.0) = " << result << " radians"<< endl;
    cout << "atanh(50.0) = " << result * 180 / 3.141592<< " degrees" << endl;
    return 0;
}

Output:

prog.cpp: In function ‘int main()’:
prog.cpp:12:28: error: no matching function for call to ‘acosh(std::__cxx11::string&)’
double result = acosh(x);

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription