C# Tutorial C# Advanced C# References

C# Math - Exp() Method



The C# Exp() method returns e raised to the power of specified number, i.e., ex. Please note that e is the base of the natural system of logarithms, and its value is approximately 2.718282. In special cases it returns the following:

  • If the argument is NaN, the method returns NaN.
  • If the argument is positive infinity, the method returns positive infinity.
  • If the argument is negative infinity, the method returns zero.

Syntax

public static double Exp (double x);  

Parameters

x Specify the Exponent of e.

Return Value

Returns e raised to the power of specified number.

Example:

In the example below, Exp() method is used to calculate e raised to the power of specified number.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine("Math.Exp(-2) = "
                      + Math.Exp(-2));
    Console.WriteLine("Math.Exp(-1) = "
                      + Math.Exp(-1));
    Console.WriteLine("Math.Exp(0) = "
                      + Math.Exp(0));
    Console.WriteLine("Math.Exp(1) = "
                      + Math.Exp(1));
    Console.WriteLine("Math.Exp(2) = "
                      + Math.Exp(2));
    Console.WriteLine("Math.Exp(Double.NaN) = "
                      + Math.Exp(Double.NaN));
    Console.WriteLine("Math.Exp(Double.NegativeInfinity) = "
                      + Math.Exp(Double.NegativeInfinity));
    Console.WriteLine("Math.Exp(Double.PositiveInfinity) = "
                      + Math.Exp(Double.PositiveInfinity));
  }
}

The output of the above code will be:

Math.Exp(-2) = 0.135335283236613
Math.Exp(-1) = 0.367879441171442
Math.Exp(0) = 1
Math.Exp(1) = 2.71828182845905
Math.Exp(2) = 7.38905609893065
Math.Exp(Double.NaN) = NaN
Math.Exp(Double.NegativeInfinity) = 0
Math.Exp(Double.PositiveInfinity) = Infinity

❮ C# Math Methods