Java Math - exp() Method
The java.lang.Math.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 result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is negative infinity, then the result is positive 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.
Exception
NA.
Example:
In the example below, exp() method is used to calculate e raised to the power of the specified number.
import java.lang.*; public class MyClass { public static void main(String[] args) { System.out.println(Math.exp(2)); System.out.println(Math.exp(-2)); System.out.println(Math.exp(1.5)); System.out.println(Math.exp(-1.5)); } }
The output of the above code will be:
7.38905609893065 0.1353352832366127 4.4816890703380645 0.22313016014842982
❮ Java.lang - Math