Math.Acos() is an inbuilt Math class method which returns the angle whose cosine is given as a double value argument. If the argument is NaN, then the result will be NaN.
Syntax:
public static double Acos(double num)
Parameter:
num: It is the number that represents cosine and type of this parameter is System.Double. It must be greater than or equal to -1, but less than or equal to 1.
Return Type: Returns an angle Θ, measured in radians and its type is System.Double. Here the angle is always measured in radians, such that 0 ≤ Θ ≤ π.
Note: If the value of the num is greater than 1 or less than -1 or equals to NaN, then this method always returns NaN as result. To convert the radians(return value) to degrees multiply it by 180 / Math.PI.
Examples:
Input : Math.Acos(2)
Output : NaN
Input : Math.Acos(0.3584)
Output : 1.20424285296577
Input : Math.Acos(0.0)
Output : 1.5707963267949
Input : Math.Acos(-0.0)
Output : 1.5707963267949
Input : Math.Acos(Double.PositiveInfinity)
Output : NaN
Input : Math.Acos(Double.NegativeInfinity)
Output : NaN
Program: To illustrate the Math.Acos() method
// C# program to demonstrate working // of Math.Acos() method using System; class Geeks { // Main Method public static void Main(String[] args) { double a = Math.PI; // using Math.Acos() method Console.WriteLine(Math.Acos(a)); // argument is greater than 1 Console.WriteLine(Math.Acos(2)); Console.WriteLine(Math.Acos(0.3584)); double d = 0.0; double e = -0.0; double posi = Double.PositiveInfinity; double nega = Double.NegativeInfinity; double nan = Double.NaN; // Input positive zero // Output 1.5707963267949 double res = Math.Acos(d); // converting to degree // i.e output will be 90 degree double rest = res * (180 / Math.PI); Console.WriteLine(rest); // Input negative zero // Output 1.5707963267949 Console.WriteLine(Math.Acos(e)); // input PositiveInfinity // Output NaN Console.WriteLine(Math.Acos(posi)); // input NegativeInfinity // Output NaN Console.WriteLine(Math.Acos(nega)); // input NaN // Output NaN Console.WriteLine(Math.Acos(nan)); } } |
NaN NaN 1.20424285296577 90 1.5707963267949 NaN NaN NaN
Reference: https://msdn.microsoft.com/en-us/library/system.math.Acos
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | Uri.MakeRelativeUri(Uri) Method
- Array.GetValue() Method in C# with Examples | Set - 1
- C# | CharEnumerator.MoveNext() Method
- C# | Math.IEEERemainder() Method
- C# | Substring() Method
- C# | IndexOfAny() Method
- C# | CharEnumerator.GetType() Method
- File.GetLastWriteTimeUtc() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- C# | Graphics.DrawLine() Method | Set - 1
- UInt16.GetHashCode Method in C# with Examples
- Stack.Peek Method in C#
- C# | IsNullOrEmpty() Method
- C# | Math.Sign() Method
- Int64.CompareTo Method in C# with Examples
- C# | PadRight() Method
- How to use Array.BinarySearch() Method in C# | Set -1
- C# | EndsWith() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

