Java Math exp() Method
The exp() method of Math class returns Euler’s number(e) raised to the power of a double value.
Syntax:
public static double exp(double a)
Parameters:
The parameter ‘a’ represents the exponent e.
Return Value:
The exp () method returns the value ea, where e represents the base of the natural logarithms.
Special cases of the exp() method are as follows:
- It returns NaN, is the argument passed is NaN.
- It returns positive infinity, if the argument passed is positive infinity.
- It returns positive zero, if the argument passed is negative infinity.
Example 1:
public class JavaMathExpExample1 {
public static void main(String[] args) {
double a=0;
//returns the value for e raised to power 0 (e0)
System.out.println("e raised to power "+ a+" = "+Math.exp(a));
}
}
Output:
e raised to power 0.0 = 1.0
Example 2:
public class JavaMathExpExample2 {
public static void main(String[] args) {
double a=-9;
//returns the value for e raised to power 9 (e9)
System.out.println("e raised to power "+ a+" = "+Math.exp(a));
}
}
Output:
e raised to power -9.0 = 1.2340980408667956E-4
Example 3:
public class JavaMathExpExample3 {
public static void main(String[] args) {
double a=-9/0.0d;
//It returns positive zero, if the argument passed is negative infinity
System.out.println("e raised to power "+ a+" = "+Math.exp(a));
}
}
Output:
e raised to power -9.0 = 1.2340980408667956E-4
Example 4:
public class JavaMathExpExample4 {
public static void main(String[] args) {
double a=9/0.0d;
//It returns positive infinity, if the argument passed is negative
infinity
System.out.println("e raised to power "+ a+" = "+Math.exp(a));
}
}
Output:
e raised to power Infinity = Infinity
Example 5:
public class JavaMathExpExample5 {
public static void main(String[] args) {
double a=0.0d/0.0d;
//It returns NaN, is the argument passed is NaN
System.out.println("e raised to power "+ a+" = "+Math.exp(a));
}
}
Output:
e raised to power NaN = NaN
