C# | Math.Tanh() Method
Last Updated :
13 Dec, 2021
Math.Tanh() is the inbuilt Math class method which returns the hyperbolic tan of a given double value argument. The result will be NaN if the given argument is NaN.
Syntax:
public static double Tanh(double num)
Parameter:
num: It is the number whose hyperbolic tan is to be returned and type of this parameter is System.Double.
Return Value: The method returns the hyperbolic tan of num. of type System.Double. If num is equal to NegativeInfinity, this method returns -1. If num is equal to PositiveInfinity, this method returns 1. If num is equal to NaN, this method returns NaN.
Examples :
Input : num = 60.0
Output : 1.0
Below programs illustrate the Math.Tanh() method:
Program 1:
Csharp
using System;
class GFG {
public static void Main(String[] args)
{
double num1 = 60.0, num2 = 0.0, num3 = 1.0;
double tanhvalue = Math.Tanh(num1);
Console.WriteLine("The tanh of num1 = " + tanhvalue);
tanhvalue = Math.Tanh(num2);
Console.WriteLine("The tanh of num2 = " + tanhvalue);
tanhvalue = Math.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.761594155955765
Program 2:
Csharp
using System;
class GFG {
public static void Main(String[] args)
{
double num1 = (30 * (Math.PI)) / 180, num2 = 11.0, num3 = 45.0;
double tanhvalue = Math.Tanh(num1);
Console.WriteLine("The tanh of num1 = " + tanhvalue);
tanhvalue = Math.Tanh(num2);
Console.WriteLine("The tanh of num2 = " + tanhvalue);
tanhvalue = Math.Tanh(num3);
Console.WriteLine("The tanh of num3 = " + tanhvalue);
}
}
|
Output:
The tanh of num1 = 0.480472778156452
The tanh of num2 = 0.999999999442106
The tanh of num3 = 1
Share your thoughts in the comments
Please Login to comment...