.Exp()

cslylla's avatar
Published Feb 18, 2023Updated Mar 31, 2023
Contribute to Docs

The Math.Exp() method returns the value of raising e to the power of a given number.

e stands for Euler’s number, an irrational number, with an approximate constant value of 2.71828. It provides a constant base to the natural logarithm or log and can be understood as a limit of a given progression.

e Formula

Consequently, the Math.Exp() method is the inverse of the Math.Log() method.

Syntax

Math.Exp(double n);

The method takes only one parameter; the variable n (number) of type double. The function will return a positive value of type double unless the value passed is one of the following:

  • If n is 0, the function will return 1.
  • If n is PositiveInfinity, the function will return PositiveInfinity.
  • If n is NegativeInfinity, the function will return 0.
  • If n is NaN, the function will return NaN.

Example

The following example applies the Math.Exp() method for six different values. The return values are printed with the Console.WriteLine() method.

using System;
namespace MathExpMethod
{
public class Example
{
public static void Main(string[] args)
{
double firstCase = Math.Exp(1);
double secondCase = Math.Exp(-1);
double thirdCase = Math.Exp(0);
double fourthCase = Math.Exp(double.PositiveInfinity);
double fifthCase = Math.Exp(double.NegativeInfinity);
double sixthCase = Math.Exp(double.NaN);
Console.WriteLine(firstCase);
Console.WriteLine(secondCase);
Console.WriteLine(thirdCase);
Console.WriteLine(fourthCase);
Console.WriteLine(fifthCase);
Console.WriteLine(sixthCase);
}
}
}

This example results in the following output:

2.71828182845905
0.367879441171442
1
Infinity
0
NaN

Codebyte Example

The following example is runnable and uses the Math.Exp() method to return the value of raising e to the power of the given double type number:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C# on Codecademy