How to calculate exponential function in java

This example shows you how to calculate exponential function in java.

In mathematics, the exponential function is the function ex, where e is the number (approximately 2.718281828) such that the function ex equals its own derivative.

The function f(x) = ex at the point x = 0 is equal to 1.

Below is the example of calculating exponential function in java.

package com.java.connect.math;
 
//Calculate exponential function in java
public class ExponentExample {
 
    public static void main(String[] args) {
        double x = 1.0d;
 
        // calculates e raised to the power of x (e^x)
        double fx = Math.exp(x);
 
        // calculates e raised to the power of x minus 1 (e^x - 1)
        double fxm1 = Math.expm1(x);
 
        System.out.println("the fx : " + fx);
        System.out.println("the fxm1 : " + fxm1);
    }
}

The output of the above example will be as:

the fx : 2.7182818284590455
the fxm1 : 1.718281828459045