MathF.Tan() Method in C# with Examples
Last Updated :
04 Apr, 2019
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:
using System;
class GFG {
public static void Main(String[] args)
{
float a = 152f;
float b = (a * (MathF.PI)) / 180;
Console.WriteLine(MathF.Tan(b));
a = 105f;
b = (a * (MathF.PI)) / 180;
Console.WriteLine(MathF.Tan(b));
a = 76F;
b = (a * (MathF.PI)) / 180;
Console.WriteLine(MathF.Tan(b));
}
}
|
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.
using System;
class Geeks {
public static void Main(String[] args)
{
float positiveInfinity = float .PositiveInfinity;
float negativeInfinity = float .NegativeInfinity;
float nan = float .NaN;
float result;
result = MathF.Tan(negativeInfinity);
Console.WriteLine(result);
result = MathF.Tan(positiveInfinity);
Console.WriteLine(result);
result = MathF.Tan(nan);
Console.WriteLine(result);
}
}
|
Share your thoughts in the comments
Please Login to comment...