×

Java Math expm1() Method

The expm1() method of Math class returns ex-1 where e represents Euler’s number.

Syntax:

public static double expm1(double x)

Parameters:

The parameter ‘x’ represents the exponent to raise e in the calculation of ex-1.

Return Value:

The expm1 () method returns the value of ex – 1. Special cases of the expm1() method are as follows:

  • It returns NaN, is the argument passed is NaN.
  • It returns positive infinity, if the argument passed is positive infinity.
  • It returns -1.0, if the argument passed is negative infinity.
  • It returns zero with the same sign as the argument, if the argument passed is zero.

Example 1:

public class JavaMathExpm1Example1 {
    public static void main(String[] args) {
        double a=0;
        //returns the value for e raised to power 0
        System.out.println("e raised to power "+ a+" = "+Math.exp(a));
        //returns the value for e raised to power a-1
        System.out.println("e raised to power "+ a+" -1 = "+Math.expm1(a));
    }
}

Output:

e raised to power 0.0 = 1.0
e raised to power 0.0 -1 = 0.0

Example 2:

public class JavaMathExpm1Example2 {
    public static void main(String[] args) {
        double a=-9;
        //returns the value for e raised to power a-1
        System.out.println(Math.expm1(a));
    }
}

Output:

-0.9998765901959134

Example 3:

public class JavaMathExpm1Example3 {
    public static void main(String[] args) {
        double a=-9/0.0d;
        //It returns positive -1.0, if the argument passed is negative infinity
        System.out.println(Math.expm1(a));
    }
}

Output:

-1.0

Example 4:

public class JavaMathExpm1Example4 {
   public static void main(String[] args) {
        double a=9/0.0d;
        //It returns positive infinity, if the argument passed is positive
infinity
        System.out.println(Math.exp(a));
    }
}

Output:

Infinity

Example 5:

public class JavaMathExpm1Example5 {
    public static void main(String[] args) {
        double a=0.0d/0.0d;
        //It returns NaN, is the argument passed is NaN
        System.out.println(Math.exp(a));
    }
}

Output:

NaN

Related Topics

Sales Tax Problem in Java

To calculate the sales tax on a purchase in Java, you will need to know the following information: The cost of the item being purchased The sales tax rate You can then use...

4 minutes read.

The Maximum Rectangular Area in a Histogram in Java

Continuous bars should be used to form the largest possible rectangle. We'll assume in the interest of convenience that each bar's width is 1. Naive Approach In this method, each bar will be...

6 minutes read.

Java Externalization

What is Externalization in Java? Externalization is a concept that is advanced to serialization. Serialization is a concept where we can transfer an object from our JVM ( Java virtual machine...

3 minutes read.

Scanner in Java

Static way of Programming: When a variable can’t change its value during run time is called a Static way of programming. In this programming a variable is directly assigned to a...

4 minutes read.

How to check valid date in Java?

Every time we get data for any application, we must first ensure that it is accurate before continuing with any further processing. We might have to confirm the following while dealing...

4 minutes read.

How to Convert boolean to String in Java

How to Convert boolean to String in Java There are two methods to convert boolean to String. Using valueOf(boolean) method Using toString(boolean) method For both the above methods, if the passes Boolean...

2 minutes read.

Singleton class in Java

What is Singleton class in Java? Singleton means it is one. That means we can create only one instance or object of a class. For example, let us have a class...

3 minutes read.

Various Operation on Queue using Linked List in Java

We keep track of front and rear pointers in a queue data structure. The head of the line points to the first item, and the back to the last. Rear is...

3 minutes read.

How to sort a String in Java

Sorting is the process of putting the elements in a certain order, either ascending or descending. Mostly the alphabetical order or natural order is used for a string. In other...

5 minutes read.

Java Comparable Interface

We implement comparable interface when we need a new logic for determining equality. if two objects are equal, the equals() method returns true and compareTo() method returns 0. The basic...

1 minute read.

Memory Areas in Java

Let’s have a look at how memory management in Java works. We will be going to discuss how the objects get destroyed, the working of a garbage collector, and things...

5 minutes read.

Compile time vs Runtime in java

Introduction: This article will discuss compile time vs. runtime in java. Compile time and runtime are two programming terms utilized in software improvement. Compile time is when the source code is...

3 minutes read.

Collection Programs in Java

Collection Programs in Java Collection in Java provides a way to manipulate or store a group of objects. Each object in a collection is called element. Collection programs in Java mainly...

4 minutes read.

Ganesha’s Pattern in Java

This part teaches us how to use stars and other special characters to write Ganesha's Pattern in Java programming. Among the most challenging Java pattern applications to code. The Ganesha will be...

3 minutes read.

Types of Garbage Collector in Java

Garbage collection is a Java feature that offers automatic memory management. The JVM is in charge of it. The programmer does not have to handle object creation and deallocation. We...

3 minutes read.

Java Future Example

Future is an interface in the Java language that is a part of  java.util.concurrent package. It serves as a symbol for the output of an asynchronous computation. The interface offers ways to determine whether a computation has finished,  wait for it to finish, and receive its result. Once the task or calculation is finished, it cannot be undone. A Future interface offers ways to determine whether the computation is finished, to wait for it to finish, and to receive the computation's results. When the computation...

3 minutes read.

Union in Java

Sets.union() method in Java returns an immutable representation of both the union of two sets. Every element that is present in either backup set is included in the set that...

2 minutes read.

Rectangular Numbers in Java

In this tutorial, we will understand the meaning of a rectangular number in Java with the aid of examples, illustrations, and implementations. It is one of the popular coding interview...

3 minutes read.

Bottom view of a binary tree in Java

The lowest nodes in their horizontal distance are present and referred to as the bottom view of a binary tree. The horizontal distance between the nodes of a binary tree...

4 minutes read.

Java Generics Questions

Introduction We'll walk through a few real-world examples of interview questions and responses for Java generics in this article. Java 5 saw the debut of the fundamental idea of generics. Due to...

9 minutes read.