MathF.Tan(Single)是內置的MathF類方法,該方法返回給定浮點值參數(指定角度)的切線。
用法: public static float Tan (float x);
Here, x is the angle(measured in radian) whose tangent 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.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或無窮大時,顯示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
相關用法
- C# MathF.Exp()用法及代碼示例
- C# MathF.Cos()用法及代碼示例
- C# MathF.Abs()用法及代碼示例
- C# MathF.Min()用法及代碼示例
- C# MathF.Sin()用法及代碼示例
- C# MathF.Pow()用法及代碼示例
- C# MathF.Log()用法及代碼示例
- C# MathF.Max()用法及代碼示例
- C# MathF.Cbrt()用法及代碼示例
- C# Char.GetTypeCode()用法及代碼示例
- C# Char.GetHashCode()用法及代碼示例
- C# MathF.Atan()用法及代碼示例
- C# BitArray.RightShift()用法及代碼示例
- C# BitArray.LeftShift()用法及代碼示例
- C# Int16.GetTypeCode用法及代碼示例
注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 MathF.Tan() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。