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


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


在C#中,Exp(Single)是MathF類方法,用於將e提升為指定的冪。這裏e是一個數學常數,其值約為2.71828。

用法: public static float Exp (float x);
Here, x is the required number of type System.Single which specifies a power.

返回類型:它返回升為System.Single類型的冪x的數字e。


注意:

  • 如果x等於NaN,則返回值為NaN。
  • 如果x等於PositiveInfinity,則返回值為Infinity。
  • 如果x等於NegativeInfinity,則返回值為0。

示例1:

// C# Program to illustrate the 
// MathF.Exp(Single) Method 
using System; 
  
class Geeks { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // using the method 
        Console.WriteLine(MathF.Exp(7.0f)); 
        Console.WriteLine(MathF.Exp(458.95f)); 
        Console.WriteLine(MathF.Exp(9.487f)); 
        Console.WriteLine(MathF.Exp(0.00f)); 
    } 
}
輸出:
1096.633
Infinity
13187.18
1

示例2:

// C# Program to illustrate the 
// MathF.Exp(Single) Method by 
// taking NaN, PositiveInfinity 
// and NegativeInfinity] 
using System; 
  
class Geeks { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Taking NaN 
        Console.WriteLine(MathF.Exp(Single.NaN)); 
  
        // Taking PositiveInfinity 
        Console.WriteLine(MathF.Exp(Single.PositiveInfinity)); 
  
        // Taking NegativeInfinity 
        Console.WriteLine(MathF.Exp(Single.NegativeInfinity)); 
    } 
}
輸出:
NaN
Infinity
0


相關用法


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