Java Math expm1() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 5+

Definition

In Java, Math.expm1(x) returns ex - 1, the same value as Math.exp(x) - 1, but computed in a way that stays accurate when x is close to zero. The name means "exp minus 1".

Use it for tiny rates, small percentage changes, and any formula where you subtract 1 from an exponential. It was added in Java 5 (JDK 1.5).

A static method of the java.lang.Math class, added in Java 5 (JDK 1.5). Call it on the class name, as in Math.expm1(...). No import is needed, because classes in java.lang are always visible.

Syntax

Pass the exponent; the result is a double.

Java
double small = Math.expm1(1e-10);          // about 1.0E-10
double zero = Math.expm1(0);                // 0.0
double pct = Math.expm1(logReturn) * 100;   // percent change
CallWhat it does
Math.expm1(0)Returns 0.0.
Math.expm1(1)About 1.71828 (e minus 1).
Math.expm1(-Infinity)Returns -1.0.
Math.expm1(r) * 100Converts a log return r into a percent change.

For values of x far from zero, expm1(x) and exp(x) - 1 are equally good; the benefit appears when exp(x) is so close to 1 that its digits cannot hold the small difference.

Library declarations
Java
// java.lang.Math (Java 5+)
public static double expm1(double x)

Parameters

ParameterDescription
xThe exponent whose ex - 1 you want.

Return Value

Return ValueDescription
doubleex - 1. Infinity for Infinity, -1.0 for -Infinity, NaN for NaN, and a zero keeps its sign.

Compare with Similar Methods

Related methods:

MethodHow it differs
exp(x) - 1Same formula, but loses accuracy for tiny x.
log1p(x)The inverse: log1p(expm1(x)) is x.
log(x)The natural logarithm; log1p is its small-value partner.
pow(1 + r, t) - 1The compound growth version, for non-continuous rates.

Java Examples

Example 1 — Where exp(x) - 1 Falls Apart

With x = 1e-16, the number 1 + x cannot be stored as anything but 1.0. Compare the two routes, then check expm1 on 1e-10.

Java
import java.util.Locale;

public class MathExpm1Precision {
    public static void main(String[] args) {
        double x = 1e-16;
        System.out.println("exp(x) == 1.0? " + (Math.exp(x) == 1.0));
        System.out.println("exp(x) - 1 == 0? " + (Math.exp(x) - 1 == 0.0));
        System.out.println("expm1(x) > 0? " + (Math.expm1(x) > 0));

        double y = 1e-10;
        System.out.println("expm1(y) * 1e10 = " + String.format(Locale.US, "%.6f", Math.expm1(y) * 1e10));
        System.out.println("expm1(-Infinity) = " + Math.expm1(Double.NEGATIVE_INFINITY));
        System.out.println("expm1(-0.0) = " + Math.expm1(-0.0));
    }
}

How It Works

  1. A double has about 16 digits. The gap between 1.0 and the next double is about 2.2e-16, so the tiny 1e-16 is lost the moment the exponential is rounded to 1.0.
  2. The loss is permanent. Subtracting 1 from 1.0 gives exactly 0.0, which hides the true answer, while expm1 never forms the number just above 1 and keeps the tiny positive result.
  3. Scaling check. For y = 1e-10 the true value is just over 1e-10, so multiplying by 1e10 gives about 1.000000; the special inputs return -1.0 and an unchanged negative zero.

Example 2 — Measure the Error of the Naive Formula

For a growth rate of 1e-12, a good result should be very close to the rate itself. Test both formulas against that.

Java
public class MathExpm1Naive {
    public static void main(String[] args) {
        double rate = 1e-12;
        double naive = Math.exp(rate) - 1;
        double exact = Math.expm1(rate);
        System.out.println("Same digits? " + (Math.abs(naive - exact) < 1e-20));
        System.out.println("expm1 close to rate? " + (Math.abs(exact / rate - 1) < 1e-9));
        System.out.println("naive close to rate? " + (Math.abs(naive / rate - 1) < 1e-9));
    }
}

How It Works

  1. What a tiny ex - 1 should be. For very small x, ex - 1 is almost exactly x (plus a term about x * x / 2), so exact / rate should be about 1.
  2. expm1 passes. The ratio differs from 1 by only about 5e-13, far inside the 1e-9 limit, so the second line is true.
  3. The naive result is visibly off. Math.exp(rate) is stored in steps of 2.2e-16, so subtracting 1 leaves a value that is wrong by almost 0.01 percent, far above the 1e-9 limit, and the third line is false.

Example 3 — Convert a Log Return Into a Percent Change

Stock analysts often store daily changes as log returns. expm1(r) turns one back into an ordinary percentage.

Java
import java.util.Locale;

public class MathExpm1Returns {
    public static void main(String[] args) {
        double[] logReturns = {0.05, -0.05, 0.0};
        for (double r : logReturns) {
            double percent = Math.expm1(r) * 100;
            System.out.println("log return " + r + " -> " + String.format(Locale.US, "%.2f", percent) + "%");
        }
    }
}

How It Works

  1. Growth factor minus one. A price that moves by a log return of 0.05 is multiplied by e to the 0.05, about 1.0513, which is a rise of 5.13 percent.
  2. Losses are smaller than they look. A log return of -0.05 gives a factor of about 0.9512, a fall of 4.88 percent, a bit less than 5.
  3. Zero stays zero. expm1(0.0) is exactly 0.0, which %.2f prints as 0.00.

Frequently Asked Questions

It returns e raised to the power x, minus 1: the same as Math.exp(x) - 1, but accurate for values of x close to zero.
For tiny x, Math.exp(x) is so close to 1.0 that the small difference is lost during rounding. expm1 avoids that loss. For example, Math.exp(1e-16) - 1 is 0.0 while Math.expm1(1e-16) is about 1.0E-16.
Java 5 (JDK 1.5). It is a final static method of java.lang.Math, so no import is needed.
It is -1.0, because e to the power minus infinity is 0 and 0 minus 1 is -1.
Math.log1p. Math.log1p(Math.expm1(x)) gives back x, apart from tiny rounding differences.

Next: floor()

Round a double down to the previous whole number (the result is still a double).

floor() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful