MathF.Tan() Method in C# with Examples

MathF.Tan(Single) is an inbuilt MathF class method which returns the tangent of a given float value argument(specified angle).

Syntax: public static float Tan (float x);
Here, x is the angle(measured in radian) whose tangent is to be returned and the type of this parameter is System.Single.

Return Value: This method will return the tangent of x of type System.Single. If x is equal to NegativeInfinity, PositiveInfinity, or NaN, then this method returns NaN.

Below programs illustrate the use of the above-discussed method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// MathF.Tan(Single) Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main(String[] args)
    {
        float a = 152f;
  
        // converting the value to radians
        float b = (a * (MathF.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(MathF.Tan(b));
        a = 105f;
  
        // converting value to radians
        b = (a * (MathF.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(MathF.Tan(b));
        a = 76F;
  
        // converting value to radians
        b = (a * (MathF.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(MathF.Tan(b));
    }
}

chevron_right


Output:

-0.5317094
-3.732049
4.010781

Example 2: To show the working of MathF.Tan(Single) method when the argument is NaN or infinity.

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the
// MathF.Tan(Single) Method
using System;
  
class Geeks {
  
    // Main Method
    public static void Main(String[] args)
    {
  
        // Taking the positive, negative
        // infinity and NaN
        float positiveInfinity = float.PositiveInfinity;
        float negativeInfinity = float.NegativeInfinity;
        float nan = float.NaN;
  
        float result;
  
        // Here argument is negative infinity,
        // so the output will be NaN
        result = MathF.Tan(negativeInfinity);
        Console.WriteLine(result);
  
        // Here argument is positive infinity,
        // so the output will also be NaN
        result = MathF.Tan(positiveInfinity);
        Console.WriteLine(result);
  
        // Here the argument is NaN, so 
        // the output will be NaN
        result = MathF.Tan(nan);
        Console.WriteLine(result);
    }
}

chevron_right


Output:

NaN
NaN
NaN


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.