C# Math.Atan() – Examples

In this tutorial, we will learn about the C# Math.Atan() method, and learn how to use this method to find the arc tangent of given double value, with the help of examples.

Atan(Double)

Math.Atan(d) returns the angle whose tangent is the specified number d. The angle returned shall be in radians.

Syntax

The syntax of Atan(d) method is

Math.Atan(Double d)

where

ParameterDescription
dThe double value for which we have to find arc tangent.

Return Value

The method returns value of type double.

Example 1 – Math.Atan(1.0)

In this example, we will find the angle for which tangent value is 1.0. We shall print the result both in radians and in degrees.

We know that tan(45 degrees) = 1.0. So, we should get the PI/4 radians as return value.

C# Program

using System;

class Example {
    static void Main(string[] args) {
        Double d = 1.0;

        Double angle = Math.Atan(d);
        Console.WriteLine($"Angle in radians : {angle}");
        Console.WriteLine($"Angle in degrees : {(180 / Math.PI) * angle}");
    }
}

Output

Angle in radians : 0.785398163397448
Angle in degrees : 45

Example 2 – Math.Atan(0)

In this example, we will find the angle for which tangent value is 0.0. We know that tan(0 degrees) = 0. So, we should get the zero radians as return value.

C# Program

using System;

class Example {
    static void Main(string[] args) {
        Double d = 0;

        Double angle = Math.Atan(d);
        Console.WriteLine($"Angle in radians : {angle}");
        Console.WriteLine($"Angle in degrees : {(180 / Math.PI) * angle}");
    }
}

Output

Angle in radians : 0
Angle in degrees : 0

Example 3 – Atan(Positive Infinity)

In this example, we will find the angle for which tangent value is Positive Infinity. We know that tan(90 degrees) = + Infinity. So, we should get the PI/2 radians as return value.

C# Program

using System;

class Example {
    static void Main(string[] args) {
        Double d = Double.PositiveInfinity;

        Double angle = Math.Atan(d);
        Console.WriteLine($"Angle in radians : {angle}");
        Console.WriteLine($"Angle in degrees : {(180 / Math.PI) * angle}");
    }
}

Output

Angle in radians : 1.5707963267949
Angle in degrees : 90

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.Atan() method, and also learnt how to use this method with the help of C# example programs.