Open In App

MathF.Tanh() Method in C# with Examples

Last Updated : 13 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Math.Tanh(Single) Method is the inbuilt MathF class method which returns the hyperbolic tangent of a given single value argument. 
 

Syntax: public static float Tanh (float x); 
Here, x is the number whose hyperbolic tangent is to be returned and type of this parameter is System.Single
 

Return Value: This method returns the hyperbolic tangent of x of type System.Single. If x is equal to NegativeInfinity or PositiveInfinity, PositiveInfinity is returned. If x is equal to NaN, NaN is returned.
Below programs illustrate the use of the above-discussed method:
Example 1:
 

Csharp




// C# program to illustrate the
// MathF.Tanh(Single) Method
using System;
 
class GFG {
 
    // Main Method
    public static void Main(String[] args)
    {
 
        float num1 = 70.0f, num2 = 0.0f, num3 = 1.0f;
 
        // It returns the hyperbolic tangent
        // of specified angle in radian
        float tanhvalue = MathF.Tanh(num1);
        Console.WriteLine("The Tanh of num1 = " + tanhvalue);
 
        tanhvalue = MathF.Tanh(num2);
        Console.WriteLine("The Tanh of num2 = " + tanhvalue);
 
        tanhvalue = MathF.Tanh(num3);
        Console.WriteLine("The Tanh of num3 = " + tanhvalue);
    }
}


Output: 

The Tanh of num1 = 1
The Tanh of num2 = 0
The Tanh of num3 = 0.7615942

 

Example 2:
 

Csharp




// C# program to illustrate the
// MathF.Tanh(Single) Method
using System;
 
class GFG {
 
    // Main Method
    public static void Main()
    {
         
        float num1 = (90 * (MathF.PI)) / 180;
         
        // calling result() method
        result(num1);
        result(Single.NaN);
        result(Single.NegativeInfinity);
        result(Single.PositiveInfinity);
    }
 
    // defining result() method
    public static void result(float value)
    {
 
        // using the method
        float result = MathF.Tanh(value);
 
        // Display the value
        Console.WriteLine("Tanh({0}) will be {1}",
                                   value, result);
    }
}


Output: 

Tanh(1.570796) will be 0.9171523
Tanh(NaN) will be NaN
Tanh(-Infinity) will be -1
Tanh(Infinity) will be 1

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads