C# Math.Tanh() – Examples

In this tutorial, we will learn about the C# Math.Tanh() method, and learn how to use this method to find the hyperbolic tangent of given angle, with the help of examples.

Tanh(Double)

Math.Tanh(value) returns the hyperbolic tangent of the specified angle value.

Syntax

The syntax of Tanh() method is

Math.Tanh(Double value)

where

ParameterDescription
valueThe value represents radians for which hyperbolic tangent is to be calculated.

Return Value

The method returns Double value.

Example 1 – Tanh(Double)

In this example, we will find the hyperbolic tangent of angles: 1 radian, PI radians, PI/2 radians, 0 radians, Infinity radians, -Infinity radians.

C# Program

using System;
 
class Example {
    static void Main(string[] args) {
        Double value, result;

        value = 1; //1 radian
        result = Math.Tanh(value);
        Console.WriteLine($"Tanh({value} radian) = {result}.");

        value = Math.PI; // PI radians or 180 degrees
        result = Math.Tanh(value);
        Console.WriteLine($"Tanh({value} radian) = {result}.");

        value = Math.PI/2; // 90 degrees
        result = Math.Tanh(value);
        Console.WriteLine($"Tanh({value} radian) = {result}.");

        value = 0; // 0 degrees
        result = Math.Tanh(value);
        Console.WriteLine($"Tanh({value} radian) = {result}.");

        value = Double.PositiveInfinity;
        result = Math.Tanh(value);
        Console.WriteLine($"Tanh({value} radian) = {result}.");

        value = Double.NegativeInfinity;
        result = Math.Tanh(value);
        Console.WriteLine($"Tanh({value} radian) = {result}.");
    }
}

Output

Tanh(1 radian) = 0.761594155955765.
Tanh(3.14159265358979 radian) = 0.99627207622075.
Tanh(1.5707963267949 radian) = 0.917152335667274.
Tanh(0 radian) = 0.
Tanh(∞ radian) = 1.
Tanh(-∞ radian) = -1.

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.Tanh() method, and also learnt how to use this method with the help of C# example programs.