C# Tutorial C# Advanced C# References

C# Math - Atan() Method



The C# Atan() method returns arc tangent of a value. The returned value will be in the range -𝜋/2 through 𝜋/2. In special cases it returns the following:

  • If the argument is NaN, the method returns NaN.

Note: Atan() is the inverse of tan().

Syntax

public static double Atan(double arg);

Parameters

arg Specify the value.

Return Value

Returns the arc tangent of the value.

Example:

In the example below, Atan() method is used to find out the arc tangent of a given value.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine("Math.Atan(-2) = "
                      + Math.Atan(-2));
    Console.WriteLine("Math.Atan(-1) = "
                      + Math.Atan(-1));
    Console.WriteLine("Math.Atan(0) = "
                      + Math.Atan(0));
    Console.WriteLine("Math.Atan(1) = "
                      + Math.Atan(1));
    Console.WriteLine("Math.Atan(2) = "
                      + Math.Atan(2));
    Console.WriteLine("Math.Atan(Double.NaN) = "
                      + Math.Atan(Double.NaN));
  }
}

The output of the above code will be:

Math.Atan(-2) = -1.10714871779409
Math.Atan(-1) = -0.785398163397448
Math.Atan(0) = 0
Math.Atan(1) = 0.785398163397448
Math.Atan(2) = 1.10714871779409
Math.Atan(Double.NaN) = NaN

❮ C# Math Methods