Java.lang Package Classes

Java Math - expm1() Method



The java.lang.Math.expm1() method returns e raised to the power of specified number minus 1, i.e., ex-1. Please note that e is the base of the natural system of logarithms, and its value is approximately 2.718282. In special cases it returns the following:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative infinity, then the result is -1.0.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Syntax

public static double expm1(double x)   

Parameters

x Specify the exponent of e.

Return Value

Returns e raised to the power of specified number minus 1, i.e., ex-1.

Exception

NA.

Example:

In the example below, expm1() method is used to calculate e raised to the power of specified number minus one.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.expm1(2)); 
  System.out.println(Math.expm1(-2)); 
  System.out.println(Math.expm1(1.5)); 
  System.out.println(Math.expm1(-1.5));    
 }
}

The output of the above code will be:

6.38905609893065
-0.8646647167633873
3.481689070338065
-0.7768698398515702

❮ Java.lang - Math