![]() |
VOOZH | about |
The Math.exp() method is a part of the java.lang.Math class. This method is used to calculate the value of Euler's number e raised to the power of a specified exponent.
In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.
Special Cases:
These special cases make sure that the Math.exp() methods work correctly.
public static double exp(double a)
Now, we are going to discuss some examples for better understanding.
Example 1: In this example, we will see the basic usage of exp() method with regular values.
exp(5) = 148.4131591025766
Explanation: Here, we are calculating the exponential of regular number with the help of exp() method. We have declared a variable x with a value 5 and for this number we are calculating the exponential value.
Example 2: In this example, we will see how exp() method handles the NaN and Infinity cases.
exp(NaN) = NaN exp(+∞) = Infinity exp(-∞) = 0.0
Explanation: Here, we are handling the special cases such as NaN and infinity.
Note: This method is very useful when we have to do interest calculations and also used in machine learning algorithm.