📜  C#| Math.Sin()方法

📅  最后修改于: 2021-05-29 16:37:53             🧑  作者: Mango

Math.Sin()是内置的Math类方法,它返回给定双值参数(指定角度)的正弦值。

句法:

public static double Sin(double num)

范围:

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

下面是说明Math.Sin()方法的程序。

程序1:演示Math.Sin()方法的工作。

// C# program to demonstrate working
// Math.Sin() method
using System;
   
class Geeks {
   
    // Main Method
    public static void Main(String []args)
    {
        double a = 30;
           
        // converting value to radians
        double b = (a * (Math.PI)) / 180;
   
        // using method and displaying result
        Console.WriteLine(Math.Sin(b));
        a = 45;
           
        // converting value to radians
        b = (a * (Math.PI)) / 180;
   
        // using method and displaying result
        Console.WriteLine(Math.Sin(b));
        a = 60;
           
        // converting value to radians
        b = (a * (Math.PI)) / 180;
  
        // using method and displaying result
        Console.WriteLine(Math.Sin(b));
        a = 90;
           
        // converting value to radians
        b = (a * (Math.PI)) / 180;
   
        // using method and displaying result
        Console.WriteLine(Math.Sin(b));
    }
}
输出:
0.5
0.707106781186547
0.866025403784439
1

程序2:显示自变量为NaN或infinity时Math.Sin()方法的工作方式。

// C# program to demonstrate working
// Math.Sin() 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.Sin(negativeInfinity);
         Console.WriteLine(result);
  
        // Here argument is positive infinity,
        // output will also be NaN
        result = Math.Sin(positiveInfinity);
        Console.WriteLine(result);
  
        // Here argument is NaN, output will be NaN
        result = Math.Sin(nan);
        Console.WriteLine(result);
    }
}
输出:
NaN
NaN
NaN