MathF.Tanh() Method in C# with Examples

CsharpServer Side ProgrammingProgramming

The MathF.Tanh() method in C# returns the hyperbolic tangent of a given single value argument.

Syntax

Following is the syntax −

public static float Tanh (float val);

Above, Val is the is number whose hyperbolic tangent is to be returned.

Example

Let us now see an example to implement the MathF.Tanh() method −

using System;
public class Demo {
   public static void Main(){
      float val1 = 10f;
      float val2 = float.NaN;
      Console.WriteLine("MathF.Tanh(val1) = "+MathF.Tanh(val1));
      Console.WriteLine("MathF.Tanh(val2) = "+MathF.Tanh(val2));
   }
}

Output

This will produce the following output −

MathF.Tanh(val1) = 1
MathF.Tanh(val2) = NaN

Example

Let us now see another example to implement the MathF.Tanh() method −

using System;
public class Demo {
   public static void Main(){
      float val1 = float.PositiveInfinity;
      float val2 = float.NegativeInfinity;
      float val3 = (20f * (MathF.PI)) / 180;
      Console.WriteLine("MathF.Tanh(val1) = "+MathF.Tanh(val1));
      Console.WriteLine("MathF.Tanh(val2) = "+MathF.Tanh(val2));
      Console.WriteLine("MathF.Tanh(val3) = "+MathF.Tanh(val3));
   }
}

Output

This will produce the following output −

MathF.Tanh(val1) = 1
MathF.Tanh(val2) = -1
MathF.Tanh(val3) = 0.3355469
raja
Published on 05-Nov-2019 07:43:53
Advertisements