当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Math.Tan()用法及代码示例


Math.Tan()是内置的Math类方法,该方法返回给定双值参数(指定角度)的切线。

用法:

public static double Tan(double num)

参数:


  • num:要返回其切线的角度(以弧度为单位),此参数的类型为System.Double。

返回值:返回类型为System.Double的num的切线。如果num等于NegativeInfinity,PositiveInfinity或NaN,则此方法返回NaN。

下面的程序来说明Math.Tan()方法。

示例1:演示Math.Tan()方法的用法。

// C# program to demonstrate working 
// Math.Tan() method 
using System; 
   
class Geeks { 
   
    // Main Method 
    public static void Main(String []args) 
    { 
        double a = 12; 
           
        // converting value to radians 
        double b = (a * (Math.PI)) / 180; 
   
        // using method and displaying result 
        Console.WriteLine(Math.Tan(b)); 
        a = 63; 
           
        // converting value to radians 
        b = (a * (Math.PI)) / 180; 
   
        // using method and displaying result 
        Console.WriteLine(Math.Tan(b)); 
        a = 187; 
           
        // converting value to radians 
        b = (a * (Math.PI)) / 180; 
  
        // using method and displaying result 
        Console.WriteLine(Math.Tan(b)); 
        a = 45; 
           
        // converting value to radians 
        b = (a * (Math.PI)) / 180; 
   
        // using method and displaying result 
        Console.WriteLine(Math.Tan(b)); 
    } 
}
输出:
0.212556561670022
1.96261050550515
0.122784560902905
1


示例2:当参数为NaN或无穷大时,显示Math.Tan()方法的用法。

// C# program to demonstrate working 
// Math.Tan() method in infinity case 
using System; 
  
class Geeks { 
      
    // Main Method 
    public static void Main(String []args) 
    { 
  
        double positiveInfinity = Double.PositiveInfinity; 
                 
        double negativeInfinity = Double.NegativeInfinity; 
                 
                 
        double nan = Double.NaN; 
        double result; 
  
        // Here argument is negative infinity, 
        // output will be NaN 
         result = Math.Tan(negativeInfinity); 
         Console.WriteLine(result); 
  
        // Here argument is positive infinity, 
        // output will also be NaN 
        result = Math.Tan(positiveInfinity); 
        Console.WriteLine(result); 
  
        // Here argument is NaN, output will be NaN 
        result = Math.Tan(nan); 
        Console.WriteLine(result); 
    } 
}
输出:
NaN
NaN
NaN


相关用法


注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 C# | Math.Tan() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。