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

 `// C# program to illustrate the``// MathF.Cosh(Single) Method``using` `System;` `class` `GFG {` `    ``// Main Method``    ``public` `static` `void` `Main(String[] args)``    ``{` `        ``float` `num1 = 60.0f, num2 = 0.0f, num3 = 1.0f;` `        ``// It returns the hyperbolic cosine``        ``// of specified angle in radian``        ``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

 `// C# program to illustrate the``// MathF.Cosh(Single) Method``using` `System;` `class` `GFG {` `    ``// Main Method``    ``public` `static` `void` `Main()``    ``{``        ` `        ``float` `num1 = (30 * (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.Cosh(value);` `        ``// Display the 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```

My Personal Notes arrow_drop_up