C++ atanh()

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

The atanh() function takes a single argument and returns the arc hyperbolic tangent of that value in radians.

The function is defined in <cmath> header file.

[Mathematics] tanh-1 x = atanh(x) [In C++ Programming]

atanh() prototype [As of C++ 11 standard]

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

atanh() Parameters

The atanh() function takes a single mandatory argument in the range [-1, 1].

If the value is greater than 1 or less than -1, a domain error occurs.


atanh() Return value

The atanh() function returns the inverse hyperbolic tangent of the argument passed to it.

atnah() Return value table
Parameter (x) Return Value
-1 < x < 1 Finite value
x = -1 -∞
x = 1
x < -1 or x > 1 NaN (Not a Number

Example 1: How atanh() function works in C++?

#include <iostream>
#include <cmath>

#define PI 3.141592654
using namespace std;

int main()
{
	double x = 0.32, result;

	result = atanh(x);
	cout << "atanh(x) = " << result << " radian" << endl;

	// result in degrees
	cout << "atanh(x) = " << result*180/PI << " degree" << endl;
	
	return 0;
}

When you run the program, the output will be:

atanh(x) = 0.331647 radian
atanh(x) = 19.002 degree

Example 2: atanh() function with integral type

#include <iostream>
#include <cmath>

#define PI 3.141592654
using namespace std;

int main()
{
	int x = 1;
	double result;

	result = atanh(x);
	cout << "atanh(x) = " << result << " radian" << endl;

	// result in degrees
	cout << "atanh(x) = " << result*180/PI << " degree" << endl;
	
	return 0;
}

When you run the program, the output will be:

atanh(x) = inf radian
atanh(x) = inf degree