×

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

Annotations in Java

Annotations in Java Java Annotations are metadata about the source code. They do not have any direct effect on the execution of the java program. Annotations in Java were introduced in...

4 minutes read.

Virtual Function in Java

In the Operated Oriented Programming language, a virtual function or virtual method is a collection of functions that overrides the functionality of a function in an inheriting class with the same...

4 minutes read.

Trim Method in String Java

What is a String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java programming language. “String” is a...

3 minutes read.

Internal Working of ArrayList in Java

Java's version of a resizable array is called ArrayList. The dynamic growth of an array list ensures that there is always room for new elements. ArrayList's backing data structure is...

8 minutes read.

Reverse a String in Java

Reversing a string means that if we have a string called “what is your name”, the reversed format is “eman ruoy si tahw”. Reversing a string involves totally flipping the...

3 minutes read.

Hidden classes in Java

There specifically are some APIs available in the market that generally is harmful to be used in our programs specifically literally, and until JDK 15, there, for all intents and...

4 minutes read.

Java Integer parseUnsignedInt() method

The parseUnsignedInt() method of Java Integer class parses the string argument as an unsigned decimal integer. The second parameter parses the string argument as an unsigned integer in the radix specified...

2 minutes read.

How to Convert String to char in Java

How to Convert String to char in Java There are two methods to convert String to char are: Using charAt() method Using tocharArray() method Using charAt() method This is the method of String class that...

3 minutes read.

Economical number in Java

Economical number is said to be economically efficient if the number of digits after prime factorization of the original number with their powers is less than the number of digits...

3 minutes read.

Java Math.multiplyExact() method in Java

Java has an inbuilt math function called Math.multiplyExact() that returns the sum of the parameters. If the result exceeds an integer, an exception is thrown. There is no need to...

2 minutes read.

Program to find the duplicate characters in a string

Problem statement You have given with a string and your task is to find out the repeated characters from the string and print them. If no character is repeated, then you...

2 minutes read.

Java Network Programming (Socket Programming in Java)

JAVA NETWORK Network programming is used to execute programs across multiple machines that are connected by a network. The java.net package contains a collection of classes and interfaces that provide this...

3 minutes read.

Java Boyer Moore

A string searching or matching technique called the Boyer-Moore algorithm was created in 1977 by Robert S. Boyer and J. Strother Moore. It is the most popular and effective string-matching...

9 minutes read.

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...

2 minutes read.

Facts about null in Java

Nearly all programming languages have a relationship with null. Hardly any programmers are unconcerned by null. The null has a java.lang.NullPointerException association in Java. Given that it is a class...

4 minutes read.

Heart Pattern in Java

Heart Pattern is yet another intricate pattern program, however, due to its complexity, interviewers hardly ever inquire about it. Method for Printing the Heart Number Pattern Put the value of the total row...

2 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.

Maximizing Profit in Stock Buy Sell in Java

In this tutorial, we will deal with a popular problem, a favourite of interviewers. The problem is named as Maximising profit in stock Buy Sell. we will see certain approaches...

6 minutes read.

Java String endsWith() method

Checks whether this String ends with the specified suffix or not. Syntax public boolean endsWith(String Suffix) Parameter Suffix : It takes suffix as a parameter  i.e. Sequence of characters Returns It returns true when the current...

1 minute read.

Java Boolean logicalXor() Method

The logicalXor() method of Java Boolean class returns the result of implementing logical XOR operation on the specified Boolean operands. Syntax: public static boolean logicalXor (boolean a, boolean b) Parameters: The parameters ‘a’ and...

2 minutes read.