MathF.Tanh() Method in C# with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

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

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# praogram 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);
    }
}

chevron_right


Output:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.