Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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
dequalsDouble.NaN, the method returnsNaN. -
If
dequalsDouble.PositiveInfinity, the method returnsPositiveInfinity. -
If
dequalsDouble.NegativeInfinity, the method returns0.
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.
