MathF.Tanh() Method in C# with Examples
Last Updated :
13 Dec, 2021
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
using System;
class GFG {
public static void Main(String[] args)
{
float num1 = 70.0f, num2 = 0.0f, num3 = 1.0f;
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
using System;
class GFG {
public static void Main()
{
float num1 = (90 * (MathF.PI)) / 180;
result(num1);
result(Single.NaN);
result(Single.NegativeInfinity);
result(Single.PositiveInfinity);
}
public static void result( float value)
{
float result = MathF.Tanh(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
Share your thoughts in the comments
Please Login to comment...