C# Tutorial C# Advanced C# References

C# Math - Tan() Method



The C# Tan() method returns trigonometric tangent of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NaN, negative infinity or positive infinity, the method returns NaN.

In the graph below, Tan(x) vs x is plotted.

Tan Function

Syntax

public static double Tan (double arg);

Parameters

arg Specify the angle in radian.

Return Value

Returns the trigonometric tangent of an angle.

Example:

In the example below, Tan() method is used to find out the trigonometric tangent of an angle.

using System;

class MyProgram {
  static void Main(string[] args) {
    double pi = Math.PI;
    Console.WriteLine("Math.Tan(pi/6) = "
                      + Math.Tan(pi/6));
    Console.WriteLine("Math.Tan(pi/4) = "
                      + Math.Tan(pi/4));
    Console.WriteLine("Math.Tan(pi/3) = "
                      + Math.Tan(pi/3));
    Console.WriteLine("Math.Tan(Double.NaN) = "
                      + Math.Tan(Double.NaN));
    Console.WriteLine("Math.Tan(Double.NegativeInfinity) = "
                      + Math.Tan(Double.NegativeInfinity));
    Console.WriteLine("Math.Tan(Double.PositiveInfinity) = "
                      + Math.Tan(Double.PositiveInfinity));
  }
}

The output of the above code will be:

Math.Tan(pi/6) = 0.577350269189626
Math.Tan(pi/4) = 1
Math.Tan(pi/3) = 1.73205080756888
Math.Tan(Double.NaN) = NaN
Math.Tan(Double.NegativeInfinity) = NaN
Math.Tan(Double.PositiveInfinity) = NaN

❮ C# Math Methods

5