Library contents

Java Math.expm1

In Java, Math.expm1 computes e raised to x minus 1. It preserves precision near zero, where subtracting 1 from a rounded exponential can lose significant digits.

A simple example

Math.expm1

  1. Start with 0
  2. Do this Evaluate e⁰ minus 1
  3. Result 0
At zero the exponential is 1. Subtracting 1 gives zero.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(Math.expm1(0.0));
    }
}
Output
0.0

Syntax

Java syntax
Math.expm1(rate)
JDK 21 method signatures (1)
public static double expm1(double x)
Run these examples in Java

Save one example at a time as Main.java. Use JDK 21.

java Main.java

Recover a small percentage increase

A dashboard measures a percentage change so small that rounding can hide it. Use a numerical operation designed for a change near zero to retain the information in the original reading.

From the programdouble rate = 0.01
Result0.010
Main.java

class Main {
    public static void main(String[] args) throws Exception {
        double rate = 0.01;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.expm1(rate)));
    }
}
Output
0.010

A continuous rate of 0.01 gives a fractional increase of about 0.01005017.

Advertisements

Recover the net sensor change

A sensor has a continuous change of minus 0.03 over one run. The report needs the fractional change relative to the start.

Given-0.03
Worked result-0.0296

Using -0.03 gives -0.0296 for this measurement.

Report a small gain

An amplifier model gives a log gain of 0.002. A technician converts it to the fractional gain above baseline.

Given0.002
Worked result0.0020

Using 0.002 gives 0.0020 for this measurement.

What to watch for

The result is a fraction. Multiply by 100 before labelling it as a percentage.

Documentation for Math.expm1