Home »
Java programming language
Java Math Class static double exp(double d) with example
Java Math Class static double exp(double d) method: Here, we are going to learn about the static double exp(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on August 22, 2019
Math Class static double exp(double d)
- This method is available in java.lang package.
- This method is used to return the exponential of the given number in the method or other words it is used to calculate the e raised to the power of the given argument.
- In this method, exp stands for exponentiation.
- This is a static method so this method is accessible with the class name too.
- The return type of this method is double that means it returns the exponentiation of the given argument and the argument and return value is of double type.
- In this method we pass only one parameter as an argument in the method of Math class and the given parameter is the exponent to raise the power of e to.
- This method does not throw any exception.
Syntax:
public static double exp(double d){
}
Parameter(s):
double d – A double value whose exponential to be found..
Note:
- If we pass "NaN" to the function, it returns the "NaN".
- If we pass positive infinity, it returns the positive infinity.
- If we pass negative infinity, it returns 0.0.
Return value:
The return type of this method is double, it returns the exponentiation of the given value.
Java program to demonstrate example of exp(double d) method
// Java program to demonstrate the example of
//exp(double d) method of Math Class
public class ExpMethod {
public static void main(String[] args) {
// Here we are declaring few variables
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 0.8;
double d4 = 2;
// Display previous value of d1,d2,d3 and d4
System.out.println(" Before implementing exp() so the value of d1 is :" + d1);
System.out.println(" Before implementing exp() so the value of d2 is :" + d2);
System.out.println(" Before implementing exp() so the value of d3 is :" + d3);
System.out.println(" Before implementing exp() so the value of d4 is :" + d4);
// Here , we will get (Infinity) because we are
// passing parameter whose value is (infinity)
System.out.println("After implementing exp() so the value of d1 is :" + Math.exp(d1));
// Here , we will get (0.0) because we are
// passing parameter whose value is (-infinity)
System.out.println("After implementing exp() so the value of d2 is :" + Math.exp(d2));
// Here , we will get (e raised to the power of 0.8)
// because we are passing parameter whose value is (0.8)
System.out.println("After implementing exp() so the value of d3 is :" + Math.exp(d3));
// Here , we will get ( e raised to the power of 2)
// because we are passing parameter whose value is (2)
System.out.println("After implementing exp() so the value of d4 is :" + Math.exp(d4));
}
}
Output
E:\Programs>javac ExpMethod.java
E:\Programs>java ExpMethod
Before implementing exp() so the value of d1 is :Infinity
Before implementing exp() so the value of d2 is :-Infinity
Before implementing exp() so the value of d3 is :0.8
Before implementing exp() so the value of d4 is :2.0
After implementing exp() so the value of d1 is :Infinity
After implementing exp() so the value of d2 is :0.0
After implementing exp() so the value of d3 is :2.225540928492468
After implementing exp() so the value of d4 is :7.38905609893065