Math.Exp() Method in C#

The Math.Exp() method in C# returns e (Euler's number, approximately 2.718) raised to the specified power. This method is commonly used in mathematical calculations involving exponential functions, growth calculations, and scientific computations.

Syntax

Following is the syntax for the Math.Exp() method −

public static double Exp(double d)

Parameters

  • d − A double-precision floating-point number representing the power to which e is raised.

Return Value

Returns a double value representing ed. Special cases include:

  • If d equals Double.NaN, the method returns NaN.

  • If d equals Double.PositiveInfinity, the method returns PositiveInfinity.

  • If d equals Double.NegativeInfinity, the method returns 0.

Math.Exp() Function Visualization Input (d) d = 0.0 d = 1.0 d = 2.0 Output (e^d) 1.0 2.718... 7.389... e ? 2.71828 (Euler's number)

Using Math.Exp() with Special Values

Example

using System;

public class Demo {
   public static void Main() {
      Console.WriteLine("Math.Exp(0.0): " + Math.Exp(0.0));
      Console.WriteLine("Math.Exp(Double.PositiveInfinity): " + Math.Exp(Double.PositiveInfinity));
      Console.WriteLine("Math.Exp(Double.NegativeInfinity): " + Math.Exp(Double.NegativeInfinity));
      Console.WriteLine("Math.Exp(Double.NaN): " + Math.Exp(Double.NaN));
   }
}

The output of the above code is −

Math.Exp(0.0): 1
Math.Exp(Double.PositiveInfinity): ?
Math.Exp(Double.NegativeInfinity): 0
Math.Exp(Double.NaN): NaN

Using Math.Exp() with Regular Values

Example

using System;

public class Demo {
   public static void Main() {
      Console.WriteLine("Math.Exp(1.0): " + Math.Exp(1.0));
      Console.WriteLine("Math.Exp(2.0): " + Math.Exp(2.0));
      Console.WriteLine("Math.Exp(10.0): " + Math.Exp(10.0));
      Console.WriteLine("Math.Exp(-1.0): " + Math.Exp(-1.0));
   }
}

The output of the above code is −

Math.Exp(1.0): 2.71828182845905
Math.Exp(2.0): 7.38905609893065
Math.Exp(10.0): 22026.4657948067
Math.Exp(-1.0): 0.367879441171442

Common Use Cases

Example − Exponential Growth Calculation

using System;

public class Demo {
   public static void Main() {
      double initialValue = 100;
      double growthRate = 0.05;  // 5% growth rate
      double time = 10;          // 10 time periods
      
      double finalValue = initialValue * Math.Exp(growthRate * time);
      
      Console.WriteLine("Initial Value: " + initialValue);
      Console.WriteLine("Growth Rate: " + (growthRate * 100) + "%");
      Console.WriteLine("Time Periods: " + time);
      Console.WriteLine("Final Value: " + Math.Round(finalValue, 2));
   }
}

The output of the above code is −

Initial Value: 100
Growth Rate: 5%
Time Periods: 10
Final Value: 164.87

Conclusion

The Math.Exp() method calculates e raised to the specified power, making it essential for exponential calculations in mathematics, finance, and scientific applications. It handles special values like infinity and NaN appropriately, returning predictable results for edge cases.

Updated on: 2026-03-17T07:04:35+05:30

348 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements