In this C++ tutorial, you will learn how to find the hyperbolic tangent of an angle using floor() function of cmath, with syntax and examples.

C++ tanh()

C++ tanh() returns hyperbolic tangent of angle given in radians.

Syntax

The syntax of C++ tanh() is

</>
Copy
tanh(x)

where

ParameterDescription
xA double, float, or long double value representing angle in radians.

Returns

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

The return value of tanh(x) is

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

The synopsis of tanh() function is

</>
Copy
double tanh(double x);
float tanh(float x);
long double tanh(long double x);
double tanh(T x); // For integral type

tanh() is a function of cmath library. Include cmath library in the program, if using tanh() function.

Example

In this example, we read the value of angle from user into variable x, and find the hyperbolic tangent value of x using tanh() function.

C++ Program

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

int main() {
    double x;
    cout << "Enter angle (radians) : ";
    cin >> x;
    
    double result = sinh(x);
    cout << "tanh(" << x << ") : " << result << endl;
}

Output

Enter angle (radians) : 5
tanh(5) : 74.2032
Program ended with exit code: 0
Enter angle (radians) : 0
tanh(0) : 0
Program ended with exit code: 0
Enter angle (radians) : -2
tanh(-2) : -3.62686
Program ended with exit code: 0

Conclusion

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