當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C# MathF.Tanh()用法及代碼示例


Math.Tanh(Single)方法是內置的MathF類方法,它返回給定單值參數的雙曲正切值。

用法: public static float Tanh (float x);
Here, x is the number whose hyperbolic tangent is to be returned and type of this parameter is System.Single.

返回值:此方法返回System.Single類型的x的雙曲正切值。如果x等於NegativeInfinity或PositiveInfinity,則返回PositiveInfinity。如果x等於NaN,則返回NaN。


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

示例1:

// C# program to illustrate the 
// MathF.Tanh(Single) Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main(String[] args) 
    { 
  
        float num1 = 70.0f, num2 = 0.0f, num3 = 1.0f; 
  
        // It returns the hyperbolic tangent 
        // of specified angle in radian 
        float tanhvalue = MathF.Tanh(num1); 
        Console.WriteLine("The Tanh of num1 = " + tanhvalue); 
  
        tanhvalue = MathF.Tanh(num2); 
        Console.WriteLine("The Tanh of num2 = " + tanhvalue); 
  
        tanhvalue = MathF.Tanh(num3); 
        Console.WriteLine("The Tanh of num3 = " + tanhvalue); 
    } 
}
輸出:
The Tanh of num1 = 1
The Tanh of num2 = 0
The Tanh of num3 = 0.7615942

示例2:

// C# praogram to illustrate the 
// MathF.Tanh(Single) Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
          
        float num1 = (90 * (MathF.PI)) / 180; 
          
        // calling result() method 
        result(num1); 
        result(Single.NaN); 
        result(Single.NegativeInfinity); 
        result(Single.PositiveInfinity); 
    } 
  
    // defining result() method 
    public static void result(float value) 
    { 
  
        // using the method 
        float result = MathF.Tanh(value); 
  
        // Display the value 
        Console.WriteLine("Tanh({0}) will be {1}", 
                                   value, result); 
    } 
}
輸出:
Tanh(1.570796) will be 0.9171523
Tanh(NaN) will be NaN
Tanh(-Infinity) will be -1
Tanh(Infinity) will be 1


相關用法


注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 MathF.Tanh() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。