Library contents

Java Math.log

The natural logarithm turns a positive growth multiplier into a continuous growth exponent.

A simple example

Math.log

  1. Start with 1
  2. Do this Find the natural logarithm
  3. Result 0
The logarithm asks which exponent gives 1. Since e⁰ equals 1, the answer is zero.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(Math.log(1.0));
    }
}
Output
0.0

Syntax

Java syntax
Math.log(ratio)
JDK 21 method signatures (1)
public static double log(double a)
Run these examples in Java

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

java Main.java

Measure the continuous growth needed to double

A student models growth that compounds continuously. Work backwards from a doubling of the starting amount to find the corresponding change on the natural-log scale.

From the programdouble ratio = 2.0
Result0.693
Main.java

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

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.log(ratio)));
    }
}
Output
0.693

Doubling in one period requires a continuous exponent of about 0.693 because exp(0.693) is close to two.

Advertisements

Identify a month with flat growth

A class is comparing growth against an unchanged starting amount. Examine the multiplier at the reference point so a later increase can be interpreted relative to the original quantity.

From the programdouble multiplier = 1.0
Result0.000
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        double multiplier = 1.0;

        System.out.printf(java.util.Locale.ROOT, "%.3f%n", (double) (Math.log(multiplier)));
    }
}
Output
0.000

A multiplier of one means no change. Its continuous growth exponent is zero.

Compare two light readings

A lab sample is four times brighter than the reference. The log-scale display uses the natural logarithm of that ratio.

Given4
Worked result1.386

Using 4 gives 1.386 for this measurement.

What to watch for

Supply a positive ratio. Base-ten logarithms use a different scale.

Documentation for Math.log