Java Math exp() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Math

Definition

In Java, Math.exp(x) returns e raised to the power x, where e (Math.E, about 2.71828) is Euler's number. Math.exp(0) is 1.0.

The function describes smooth growth and decay: continuously compounded interest, population growth, radioactive decay, and cooling. It has been part of java.lang.Math since the early versions of Java, and Math.log is its inverse.

A static method of the java.lang.Math class, available since the early versions of Java (JDK 1.0). Call it on the class name, as in Math.exp(...). No import is needed, because classes in java.lang are always visible.

Syntax

Pass the exponent as any number. The result is a double.

Java
double one = Math.exp(0);                       // 1.0
double e = Math.exp(1);                         // about 2.71828
double value = start * Math.exp(rate * time);   // growth
double left = start * Math.exp(-k * time);      // decay
CallWhat it does
Math.exp(0)Returns exactly 1.0.
Math.exp(1)About 2.71828, close to Math.E.
Math.exp(-x)Shrinking factor between 0 and 1 for positive x.
Math.exp(Math.log(a) * b)The idea behind pow(a, b) for positive a.

Math.E is the constant itself (2.718281828459045). exp(1) is allowed to be one unit in the last place away from it, so compare the two with a tolerance rather than ==.

Library declarations
Java
// java.lang.Math
public static double exp(double a)

Parameters

ParameterDescription
aThe exponent applied to e. Negative values give results between 0 and 1.

Return Value

Return ValueDescription
doublee raised to the power a. Infinity for Infinity or when the answer is too big, 0.0 for -Infinity or when the answer is too small, NaN for NaN.

Compare with Similar Methods

Related power and logarithm methods:

MethodHow it differs
expm1(x)Computes exp(x) - 1 accurately for tiny x.
log(x)The inverse: log(exp(x)) is x.
pow(a, b)Any base; exp(x) is the special case with base e.
Math.EThe constant e as a plain double.

Java Examples

Example 1 — exp(), Math.E, and the Limits of a double

Check exp(0), compare exp(1) with Math.E using a tolerance, and push the exponent to both extremes.

Java
public class MathExpBasics {
    public static void main(String[] args) {
        System.out.println("Math.E = " + Math.E);
        System.out.println("exp(0) = " + Math.exp(0));
        System.out.println("exp(1) = " + Math.round(Math.exp(1) * 10000) / 10000.0);
        System.out.println("close to Math.E? " + (Math.abs(Math.exp(1) - Math.E) < 1e-15));
        System.out.println("exp(-Infinity) = " + Math.exp(Double.NEGATIVE_INFINITY));
        System.out.println("exp(710) = " + Math.exp(710));
        System.out.println("exp(-746) = " + Math.exp(-746));
    }
}

How It Works

  1. Zero exponent. Any base to the power 0 is 1, so exp(0) is 1.0; and exp(1) is e itself, shown here rounded to four decimals.
  2. Tolerance, not equality. The two numbers are within a hair of each other (less than 1e-15), so the check prints true even if the last digit differs.
  3. Both ends of the range. 710 is just above the overflow limit of about 709.78, so the result is Infinity; -746 is below the underflow limit of about -745.13, so it collapses to 0.0.

Example 2 — Continuous vs Yearly Compound Interest

2000 saved at 3 percent for 5 years: compare P * e^(r * t) with ordinary yearly compounding. Output uses an English-style decimal point.

Java
import java.util.Locale;

public class MathExpInterest {
    public static void main(String[] args) {
        double principal = 2000;
        double rate = 0.03;
        int years = 5;
        double continuous = principal * Math.exp(rate * years);
        double yearly = principal * Math.pow(1 + rate, years);
        System.out.println("Continuous: " + String.format(Locale.US, "%.2f", continuous));
        System.out.println("Yearly:     " + String.format(Locale.US, "%.2f", yearly));
    }
}

How It Works

  1. One combined exponent. The rate and time are multiplied first (0.03 * 5 = 0.15), so the balance grows by the factor exp(0.15), about 1.1618.
  2. Slightly more than yearly. Yearly compounding multiplies by 1.03 five times, about 1.1593; interest that is added continuously always ends a little higher.
  3. Rounded for display. 2000 * 1.1618 is about 2323.67 and 2000 * 1.1593 is about 2318.55; %.2f keeps two decimals, and Locale.US guarantees the dot.

Example 3 — Half-Life: How Much Is Left?

A sample of 100 grams has a half-life of 10 days. Use exp with the decay constant ln(2) / halfLife to track the rest.

Java
public class MathExpDecay {
    public static void main(String[] args) {
        double start = 100;
        double halfLife = 10;
        double k = Math.log(2) / halfLife;
        for (int days = 0; days <= 30; days += 10) {
            double left = start * Math.exp(-k * days);
            System.out.println("Day " + days + ": " + Math.round(left * 100) / 100.0);
        }
    }
}

How It Works

  1. Decay constant. k = ln(2) / 10 is chosen so that after exactly one half-life the factor exp(-k * 10) equals exp(-ln 2), which is 1/2.
  2. Halving every 10 days. Each extra 10 days multiplies by another 1/2, so the amounts are 100, 50, 25, and 12.5 grams.
  3. Tidying the output. The raw values can carry tiny errors such as 50.00000000000001, so Math.round(left * 100) / 100.0 keeps two decimals and prints clean numbers.

Frequently Asked Questions

It returns e raised to the power of its argument, where e is about 2.71828. Math.exp(0) is 1.0.
exp always uses the base e, while pow accepts any base. Math.exp(x) is the same idea as Math.pow(Math.E, x), but it is usually more accurate and faster.
Use principal * Math.exp(rate * years). For a 3 percent rate, write 0.03 for the rate.
Above about 709.78 it returns Infinity, and below about -745.13 it returns 0.0. It never throws an exception.
Use Math.log, the natural logarithm: Math.log(Math.exp(x)) gives back x, apart from tiny rounding differences.

Next: expm1()

Compute e to the x, minus 1, accurately for x close to zero.

expm1() 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.

7 people found this page helpful