📜  C#中的MathF.Exp()方法与示例

📅  最后修改于: 2021-05-30 01:41:37             🧑  作者: Mango

在C#中, Exp(Single)是MathF类方法,用于将e提升为指定的幂。这里e是一个数学常数,其值约为2.71828

笔记:

  • 如果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