Java Math expm1() Method
The expm1() method of Math class returns ex-1 where e represents Euler’s number.
Syntax:
public static double expm1(double x)
Parameters:
The parameter ‘x’ represents the exponent to raise e in the calculation of ex-1.
Return Value:
The expm1 () method returns the value of ex – 1. Special cases of the expm1() 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 -1.0, if the argument passed is negative infinity.
- It returns zero with the same sign as the argument, if the argument passed is zero.
Example 1:
public class JavaMathExpm1Example1 { public static void main(String[] args) { double a=0; //returns the value for e raised to power 0 System.out.println("e raised to power "+ a+" = "+Math.exp(a)); //returns the value for e raised to power a-1 System.out.println("e raised to power "+ a+" -1 = "+Math.expm1(a)); } }
Output:
e raised to power 0.0 = 1.0 e raised to power 0.0 -1 = 0.0
Example 2:
public class JavaMathExpm1Example2 { public static void main(String[] args) { double a=-9; //returns the value for e raised to power a-1 System.out.println(Math.expm1(a)); } }
Output:
-0.9998765901959134
Example 3:
public class JavaMathExpm1Example3 { public static void main(String[] args) { double a=-9/0.0d; //It returns positive -1.0, if the argument passed is negative infinity System.out.println(Math.expm1(a)); } }
Output:
-1.0
Example 4:
public class JavaMathExpm1Example4 { public static void main(String[] args) { double a=9/0.0d; //It returns positive infinity, if the argument passed is positive infinity System.out.println(Math.exp(a)); } }
Output:
Infinity
Example 5:
public class JavaMathExpm1Example5 { public static void main(String[] args) { double a=0.0d/0.0d; //It returns NaN, is the argument passed is NaN System.out.println(Math.exp(a)); } }
Output:
NaN