Java Math expm1() Function

expm1 function in java

Java Math Class

Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs(), expm1 Function etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the expm1 Function of Math class in java.

Java expm1 Function :

Java Collection contains Math class and The class Math contains methods for performing basic and advance numeric operations such as the exponential, logarithm, square root, and trigonometric functions.
The expm1 Function of math class in Java returns the Euler’s number e raised to the power of a double value and subtract one form it. It is a static function so we can access it by using the Math class.

Syntax:

Math.expm1(number);

Definition of Parameters:

Return Type :

  • If the input is + or – value, expm1 will return the output.
  • If the input is + Infinity, this method will return + Infinity.
  • If the input is – Infinity, expm1 will return -1.0.
  • If the input is 0, this method will return 0 with the same sign as the input.
  • If the input is NaN, this method will return NaN.

Example :

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing double argumnet
        double num = 2.0d;
        
        // taking exp value
        double ans = Math.expm1(num);
        
        // printing the final answer
        System.out.println("Exponential value for the given Input is : " + ans);
        
        // using exact value of e
        double ans2 = Math.pow(2.71828,2.0d-1); 
        
        // printing the final answer
        System.out.println("Exponential value using e value is : " + ans2);
    }
}
Output:

Exponential value for the given Input is : 6.38905609893065
Exponential value using e value is : 2.71828

In the above Example, We had taken a variables of double type with a value stored in it. we are printing the exponential minus 1 value using the expm1 function and also using the value of e.

Example:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing double negative argumnet
        double num = -2.0d;
        
        // printing the final answer
        System.out.println("Exponential value for the given Input is : " + Math.expm1(num));
        
        // Initializing argument as negative infinity 
        double num2 = Double.NEGATIVE_INFINITY; 
        
        // printing the final answer
        System.out.println("Exponential value for negative infinity is : " + Math.expm1(num2));
        
        // Initializing 0 argument
        double num3 = 0; 
        
        // printing the final answer
        System.out.println("Exponential value for 0 is : " + Math.expm1(num3));
    }
}
Output:

Exponential value for the given Input is : -0.8646647167633873
Exponential value for negative infinity is : -1.0
Exponential value for 0 is : 0.0

In the above Example, We had taken example for exponent minus 1 value of the negative number, 0, and negative infinity.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription