×

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

How to Convert String to boolean in Java

How to Convert String to boolean in Java There are two methods to convert String to boolean: Using parseBoolean(string) method Using valueOf(string) method If the string contains "True," "true," or "TRUE,"...

3 minutes read.

Web Service Response Time Calculation in Java

Administration response time or reaction time is the typical measure of time it takes for a solicitation to be handled by a PC framework, like your organization switch. In the...

4 minutes read.

Arithmetic exception in Java

Exception Handling is one of the most potent ways of handling runtime faults and preserving the application's normal flow. In Java, an exception is an out-of-the-ordinary state, and exceptions are...

3 minutes read.

Anonymous Function in Java

A function defined as being unbound from an identifier is called an anonymous function. Because they permit access to variables within the scope of the contained function, these are a...

4 minutes read.

Contextual keywords in Java

Contextual keywords were earlier known as restricted identifiers and restricted keywords. Context keywords are chosen based on their expected placement in the syntactic grammar. These are the keywords in the code...

3 minutes read.

Java URL Class with Example

Java URL Uniform Resource Locator To find any resource on the internet, you need to have an address of it. The URL and IP addresses are the pointers used for this purpose....

12 minutes read.

Constructor Chaining and Constructor Overloading in Java

Constructor Chaining Constructor chaining and constructor overloading are two confusing terms. Let's first understand constructor chaining.Constructor chaining is the process of calling one constructor from another constructor using the same object....

2 minutes read.

Bin Packing Problem Java

Assigning some items with known weights to bins with consistent capacities is necessary for the bin packing problem. The goal is to use the smallest possible boxes while ensuring everything is put...

6 minutes read.

Ramanujan Number or Taxicab Number in Java

In this section, we will discuss what a Ramanujan number (also known as a Hardy-Ramanujan number) is and how to use a Java programme to determine if a given integer...

3 minutes read.

Difference Between replace() and replaceall() in Java

In this article, you will be acknowledged about the replace() and replaceall() methods in java. Also, most importantly you will be acknowledged the differences between them along with the example...

4 minutes read.

Figurate Number in Java

There have been several uses for figurate or figural numerals throughout history. A number that may be expressed by regular, distinct geometric shapes with spaced evenly points is referred to...

4 minutes read.

Java Integer hashCode() method

The hashCode()  method of Java Integer class returns a hash code for this Integer.  Syntax public int hashCode() public static int hashCode(int value)  Parameters The parameter ‘value’ represents a value whose hash code...

1 minute read.

Constructor Program in Java

Constructor Program in Java In Java, a constructor is a piece of code that is used to create an object. A constructor is called implicitly when an object is created in...

7 minutes read.

Java Return Keyword

The return keyword in Java is used to end a method's execution. the caller receives the return, followed by the appropriate value. The return type of the method, such as...

3 minutes read.

Balanced Parentheses in Java

One of the frequent programming issues, commonly referred to as the Balanced brackets issue, is the problem with the balanced parenthesis. Interviewers frequently provide this task, in which we must...

5 minutes read.

Java Class Syntax

A class is a fundamental building piece in object-oriented programming. It can be characterised as a template that outlines the information and actions connected to the creation of a class....

3 minutes read.

Minimum Window Subsequence in Java

In this article, you will be very well acknowledged about the minimum window subsequence, what is the approach and how it is implemented. The example program is also executed and...

4 minutes read.

Java logger

Logging is a crucial Java feature that aids developers in identifying issues. The logging methodology is included with Java as the programming language. It offers the Logging API, which debuted...

7 minutes read.

How to Convert int to long in Java

How to Convert int to long in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

2 minutes read.

Java 9 Try With Resources

Java 9 provides the improvement in the try statement. It allows us to declare a try statement with duly declared resources. Whenever the user does not require the functionality with...

3 minutes read.