Skip to content
Related Articles

Related Articles

Java Math expm1() method with Example

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Apr, 2018
View Discussion
Improve Article
Save Article

The java.lang.Math.expm1() returns ex -1. Note that for values of x near 0, the exact sum of expm1(x) + 1 is much closer to the true result of ex than exp(x).

  • 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 -1.0.
  • If the argument is zero, then the result is a zero with the same sign as the argument.


public static double expm1(double x) 
x-the exponent part which raises to e. 

The method returns the value ex-1, where e is the base of the natural logarithms.

Example : To show working of java.lang.Math.expm1() function

// Java program to demonstrate working
// of java.lang.Math.expm1() method
import java.lang.Math;
class Gfg {
    // driver code
    public static void main(String args[])
        double x = 3;
        // when both are not infinity
        double result = Math.expm1(x);
        double positiveInfinity = Double.POSITIVE_INFINITY;
        double negativeInfinity = Double.NEGATIVE_INFINITY;
        double nan = Double.NaN;
        // when x is NAN
        result = Math.expm1(nan);
        // when argument is +INF
        result = Math.expm1(positiveInfinity);
        // when  argument is -INF
        result = Math.expm1(negativeInfinity);
        x = -0;
        result = Math.expm1(x);
        // same sign as 0


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!