In this C++ tutorial, you will learn how to find the inverse hyperbolic tangent of a number using acosh() function of cmath, with syntax and examples.

C++ atanh()

C++ atanh() returns arc (inverse) hyperbolic tangent of a number in radians.

Syntax

The syntax of C++ atanh() is

atanh(x)

where

ParameterDescription
xA double, float, or long double value. The value of x must be in the range [-1, 1].

Returns

The return value depends on the type of value passed for parameter x.

The return value of atanh(x) is

  • double if x is double.
  • float if x is float.
  • long double if x is long double.

The synopsis of atanh() function is

double atanh(double x);
float atanh(float x);
long double atanh(long double x);
double atanh(T x); // For integral type

atanh() is a function of cmath library. Include cmath library at start of the program, if using atanh() function.

ADVERTISEMENT

Example

In this example, we read a number from user into variable x, and find its inverse hyperbolic tangent value using atanh().

C++ Program

#include <iostream>
#include<cmath>
using namespace std;

int main() {
    double x;
    cout << "Enter a number : ";
    cin >> x;
    
    double result = atanh(x);
    cout << "atanh(" << x << ") : " << result << " radians" << endl;
}

Output

Enter a number : 0.5
atanh(0.5) : 0.549306 radians
Program ended with exit code: 0
Enter a number : -1
atanh(-1) : -inf radians
Program ended with exit code: 0
Enter a number : 1
atanh(1) : inf radians
Program ended with exit code: 0
Enter a number : 5
atanh(5) : nan radians
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned the syntax of C++ atanh(), and how to use this function to find the inverse hyperbolic tangent of given value, with the help of examples.