MathF.Cosh() Method in C# with Examples
Last Updated :
13 Dec, 2021
Math.Cosh(Single) Method is the inbuilt MathF class method which returns the hyperbolic cosine of a given single value argument.
Syntax: public static float Cosh (float x);
Here, x is the number whose hyperbolic cosine is to be returned and type of this parameter is System.Single.
Return Value: This method returns the hyperbolic cosine 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 = 60.0f, num2 = 0.0f, num3 = 1.0f;
float coshvalue = MathF.Cosh(num1);
Console.WriteLine("The Cosh of num1 = " + coshvalue);
coshvalue = MathF.Cosh(num2);
Console.WriteLine("The Cosh of num2 = " + coshvalue);
coshvalue = MathF.Cosh(num3);
Console.WriteLine("The Cosh of num3 = " + coshvalue);
}
}
|
Output:
The Cosh of num1 = 5.710037E+25
The Cosh of num2 = 1
The Cosh of num3 = 1.543081
Example 2:
Csharp
using System;
class GFG {
public static void Main()
{
float num1 = (30 * (MathF.PI)) / 180;
result(num1);
result(Single.NaN);
result(Single.NegativeInfinity);
result(Single.PositiveInfinity);
}
public static void result( float value)
{
float result = MathF.Cosh(value);
Console.WriteLine("Cosh({0}) will be {1}",
value, result);
}
}
|
Output:
Cosh(0.5235988) will be 1.140238
Cosh(NaN) will be NaN
Cosh(-Infinity) will be Infinity
Cosh(Infinity) will be Infinity
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...