Open in App
Not now

# acosh() function in C++ STL

• Difficulty Level : Hard
• Last Updated : 02 Feb, 2023

The acosh() is an inbuilt function in C++ STL that returns the inverse hyperbolic cosine of an angle given in radians. The function belongs to <cmath> header file.
Syntax:

`acosh(data_type x)`

Time Complexity: O(1)
Auxiliary Space: O(1)

Parameter: The function accepts one mandatory parameter x which specifies the inverse hyperbolic angle in radian which should be greater or equal to 1. If the argument is less than 1, -nan is returned. The parameter can be of double, float, or long double datatype.
Return: The acosh() function returns the inverse hyperbolic sine of the argument in radians which is in the range [0, inf].

According to C++ 11 standard, there are various prototypes available for acosh() function,

Explicit conversion is required from (int, float or long double) to double,

The below programs illustrate the above approach:
Example 1:

## CPP

 `// C++ program to demonstrate` `// the acosh() function` `#include ` `using` `namespace` `std;`   `// Driver Code` `int` `main()` `{` `    ``double` `x = 50.0;`   `    ``// Function call to calculate acosh(x) value` `    ``double` `result = acosh(x);`   `    ``cout << ``"acosh(50.0) = "` `<< result << ``" radians"` `         ``<< endl;` `    ``cout << ``"acosh(50.0) = "` `<< result * 180 / 3.141592` `         ``<< ``" degrees"` `<< endl;` `    ``return` `0;` `}`

Output

```acosh(50.0) = 4.60507 radians
acosh(50.0) = 263.851 degrees
```

Example 2:

## CPP

 `// C++ program to demonstrate` `// the acosh() function` `#include ` `using` `namespace` `std;`   `// Driver Code` `int` `main()` `{` `    ``int` `x = 40.0;`   `    ``// Function call to calculate acosh(x) value` `    ``double` `result = acosh(x);`   `    ``cout << ``"acosh(40.0) = "` `<< result << ``" radians"` `         ``<< endl;` `    ``cout << ``"acosh(40.0) = "` `<< result * 180 / 3.141592` `         ``<< ``" degrees"` `<< endl;` `    ``return` `0;` `}`

Output

```acosh(40.0) = 4.38187 radians
acosh(40.0) = 251.063 degrees
```

If we pass a negative value(value less than 1), the function returns NaN (not a number).

Example 3:

## C++

 `// C++ program to demonstrate` `// the acosh() function` `// value less than 1` `#include ` `using` `namespace` `std;`   `// Driver Code` `int` `main()` `{` `    ``double` `x = -50.0;`   `    ``// Function call to calculate acosh(x) value` `    ``double` `result = acosh(x);`   `    ``cout << ``"acosh(-50.0) = "` `<< result << ``" radians"` `         ``<< endl;` `    ``cout << ``"acosh(-50.0) = "` `<< result * 180 / 3.141592` `         ``<< ``" degrees"` `<< endl;` `    ``return` `0;` `}`

Output

```acosh(-50.0) = -nan radians
acosh(-50.0) = -nan degrees
```

Errors and Exceptions: The function returns no matching function for call to error when a string or a character is passed as an argument.
Example:

## CPP

 `// C++ program to demonstrate` `// the acosh() function` `#include ` `using` `namespace` `std;`   `// Driver Code` `int` `main()` `{` `    ``string x = ``"gfg"``;`   `    ``// Function call to calculate acosh(x) value` `    ``double` `result = acosh(x);`   `    ``cout << ``"acosh(50.0) = "` `<< result << ``" radians"` `         ``<< endl;` `    ``cout << ``"acosh(50.0) = "` `<< result * 180 / 3.141592` `         ``<< ``" degrees"` `<< endl;` `    ``return` `0;` `}`

Error:

```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);```

The above program generates an error if no matching function for call as a string is passed as an argument.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Related Articles