📜  C#| Math.Acos()方法

📅  最后修改于: 2021-05-29 21:56:12             🧑  作者: Mango

Math.Acos()是内置的Math类方法,该方法返回以余弦值作为双值参数给出的角度。如果参数为NaN ,则结果将为NaN

句法:

public static double Acos(double num)

范围:

返回类型:返回以弧度为单位的角度Θ,其类型为System.Double 。在此,角度始终以弧度为单位,以使0≤Θ≤π。

注意:如果num的值大于1或小于-1或等于NaN ,则此方法始终返回NaN作为结果。要将弧度(返回值)转换为度数,请乘以180 / Math.PI。

例子:

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

程序:演示Math.Acos()方法

// 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

参考: https://msdn.microsoft.com/en-us/library/system.math.Acos