In C++, the tanh() function is defined in the <cmath> or <math.h> header file and is used to calculate the hyperbolic tangent of an angle specified in radians. The hyperbolic tangent is mathematically defined using exponential functions and is commonly used in mathematics, physics, engineering, and machine learning applications.
The tanh() function accepts integer, float, double, and long double values as input and returns a value in the range -1 to 1. It is widely used in neural networks, signal processing, and hyperbolic function calculations.
Mathematically,
It has the following syntax.
x: The value whose hyperbolic tangent is to be computed.
It returns the hyperbolic tangent of x.
Here, we are going to discuss several examples to demonstrate the List tanh() Function Function.
This example demonstrates how to calculate the hyperbolic tangent of an angle when the input value is of integer type.
Output:
Value of degree is : 60 tanh(x) : 0.780507
Explanation:
In this example, tanh(x) function computes the hyperbolic tangent of x and returns the value 0.78.
This example demonstrates how to calculate the hyperbolic tangent of a floating-point angle using the tanh() function.
Output:
Value of degree is : 45.2 tanh(x) : 0.657552
Explanation:
In this example, tanh(x) function computes the hyperbolic tangent of x and returns the value 0.65.
This example demonstrates how to calculate the hyperbolic tangent of zero radians using the tanh() function. The value of tanh(0) is always equal to 0.
Output:
tanh(x) : 0
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India