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


C# MathF.Sin()用法及代码示例


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

用法: public static float Sin (float x);
Here, x is the angle(measured in radian) whose sine is to be returned and the type of this parameter is System.Single.

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


以下示例程序旨在说明上述方法的用法:

示例1:

// C# program to illustrate the 
// MathF.Sin(Single) Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main(String[] args) 
    { 
        float a = 17f; 
  
        // converting value to radians 
        float b = (a * (MathF.PI)) / 180; 
  
        // using method and displaying result 
        Console.WriteLine(MathF.Sin(b)); 
        a = 47f; 
  
        // converting value to radians 
        b = (a * (MathF.PI)) / 180; 
  
        // using method and displaying result 
        Console.WriteLine(MathF.Sin(b)); 
        a = 96F; 
  
        // converting value to radians 
        b = (a * (MathF.PI)) / 180; 
  
        // using method and displaying result 
        Console.WriteLine(MathF.Sin(b)); 
    } 
}
输出:
0.2923717
0.7313538
0.9945219

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

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


相关用法


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