C++ Math tanh()

Last Updated : 20 May 2026

Math tanh() Function

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,

tanhx = ex -e-x/ ex+e-x

Syntax

It has the following syntax.

Parameters

x: The value whose hyperbolic tangent is to be computed.

Return value

It returns the hyperbolic tangent of x.

Examples of the List tanh() Function

Here, we are going to discuss several examples to demonstrate the List tanh() Function Function.

Example 1: Calculate the Hyperbolic Tangent of an Integer Value Using tanh()

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.

Example 2: Calculate the Hyperbolic Tangent of a Floating-Point Value Using tanh()

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.

Example 3: Calculate the Hyperbolic Tangent of Zero Using tanh()

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