C++ acosh()

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

The acosh() function takes a single argument and returns the arc hyperbolic cosine of that value in radian.

The function is defined in <cmath> header file.

[Mathematics] cosh-1x = acosh(x) [In C++ Programming]

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

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

acosh() Parameters

The acosh() function takes a single mandatory argument which is greater or equal to 1.

If the argument is less than 1, a domain error occurs.


acosh() Return value

The acosh() function returns a value in the range [0, ∞].

If the argument passed to acosh() is less than 1, it returns NaN (not a number).

acosh() Return values
Parameter Return Value
x >= 1 [0, ∞]
x < 1 NaN

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

#include <iostream>
#include <cmath>

#define PI 3.141592654
using namespace std;

int main()
{
	double x = 13.21, result;
	result = acosh(x);

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

	// result in degrees
	cout << "acosh(x) = " << result*180/PI << " degree" << endl;

	return 0;
}

When you run the program, the output will be:

acosh(x) = 3.27269 radian
acosh(x) = 187.511 degree

Example 2: acosh() function with integral type

#include <iostream>
#include <cmath>

#define PI 3.141592654
using namespace std;

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

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

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

When you run the program, the output will be:

acosh(x) = 2.06344 radian
acosh(x) = 118.226 degree
Did you find this article helpful?