C# Tutorial C# Advanced C# References

C# Math - Acos() Method



The C# Acos() method returns arc cosine of a value. The return value will be in the range 0 through 𝜋. In special cases it returns the following:

  • If the argument is NaN or its absolute value is greater than 1, the method returns NaN.

Note: Acos() is the inverse of cos().

Syntax

public static double Acos(double arg);

Parameters

arg Specify the value.

Return Value

Returns the arc cosine of the value.

Example:

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

using System;

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

The output of the above code will be:

Math.Acos(-1) = 3.14159265358979
Math.Acos(-0.5) = 2.0943951023932
Math.Acos(0) = 1.5707963267949
Math.Acos(0.5) = 1.0471975511966
Math.Acos(1) = 0
Math.Acos(2) = NaN
Math.Acos(Double.NaN) = NaN

❮ C# Math Methods

5