📜  C#中的MathF.Tan()方法与示例

📅  最后修改于: 2021-05-29 14:45:07             🧑  作者: Mango

MathF.Tan(Single)是内置的MathF类方法,它返回给定浮点值参数(指定角度)的切线。

返回值:该方法将返回System.Single类型的x的切线。如果x等于NegativeInfinity,PositiveInfinity或NaN ,则此方法返回NaN

下面的程序说明了上述方法的用法:

范例1:

// C# program to illustrate the
// MathF.Tan(Single) Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main(String[] args)
    {
        float a = 152f;
  
        // converting the value to radians
        float b = (a * (MathF.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(MathF.Tan(b));
        a = 105f;
  
        // converting value to radians
        b = (a * (MathF.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(MathF.Tan(b));
        a = 76F;
  
        // converting value to radians
        b = (a * (MathF.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(MathF.Tan(b));
    }
}
输出:
-0.5317094
-3.732049
4.010781

示例2:演示当参数为NaN或infinity时MathF.Tan(Single)方法的工作。

// C# program to illustrate the
// MathF.Tan(Single) Method
using System;
  
class Geeks {
  
    // Main Method
    public static void Main(String[] args)
    {
  
        // Taking the positive, negative
        // infinity and NaN
        float positiveInfinity = float.PositiveInfinity;
        float negativeInfinity = float.NegativeInfinity;
        float nan = float.NaN;
  
        float result;
  
        // Here argument is negative infinity,
        // so the output will be NaN
        result = MathF.Tan(negativeInfinity);
        Console.WriteLine(result);
  
        // Here argument is positive infinity,
        // so the output will also be NaN
        result = MathF.Tan(positiveInfinity);
        Console.WriteLine(result);
  
        // Here the argument is NaN, so 
        // the output will be NaN
        result = MathF.Tan(nan);
        Console.WriteLine(result);
    }
}
输出:
NaN
NaN
NaN