Home » Java programming language

Java Math Class static double expm1(double d) with example

Java Math Class static double expm1(double d) method: Here, we are going to learn about the static double expm1(double d) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on August 22, 2019

Math Class static double expm1(double d)

  • This method is available in java.lang package.
  • This method is used to return [ the exponential of the given number – 1] in the method or in other words it is used to calculate the ( e raised to the power of the given argument – 1). 
  • In this method, expm stands for exponentiation. 
  • This is a static method so this method is accessible with the class name too. 
  • The return type of this method is double that means it returns (The exponentiation of the given argument -1) and the argument and return value are of double type. 
  • In this method we pass only one parameter as an argument in the method of Math class and the given parameter is the exponent to raise the power of e -1. 
  • This method does not throw any exception.

Syntax:

    public static double expm1(double d){
    }

Parameter(s):

double d – A double value whose exponential to be found..

Note:

  • If we pass "NaN" to the function, it returns the "NaN".
  • If we pass positive infinity, it returns the positive infinity.
  • If we pass negative infinity, it returns -1.0.
  • If we pass zero (-0 or 0), it returns 0.0.

Return value:

The return type of this method is double, it returns the exponentiation of the given value.

Java program to demonstrate example of expm1(double d) method

// Java program to demonstrate the example of expm1(double d) 
// method of Math Class

public class Expm1Method {
    public static void main(String[] args) {
        // Here we are declaring few variables
        double d1 = 7.0 / 0.0;
        double d2 = -7.0 / 0.0;
        double d3 = 0.0;
        double d4 = -0.0;
        double d5 = 0.8;
        double d6 = 2;

        // Display previous value of d1,d2,d3, d4,d5 and d6 
        System.out.println(" Before implementing expm1() so the value of d1 is :" + d1);
        System.out.println(" Before implementing expm1() so the value of d2 is :" + d2);
        System.out.println(" Before implementing expm1() so the value of d3 is :" + d3);
        System.out.println(" Before implementing expm1() so the value of d4 is :" + d4);
        System.out.println(" Before implementing expm1() so the value of d5 is :" + d5);
        System.out.println(" Before implementing expm1() so the value of d6 is :" + d6);


        // Here , we will get (Infinity) because we are passing parameter 
        // whose value is (infinity)
        System.out.println("After implementing expm1() so the value of d1 is :" + Math.expm1(d1));

        // Here , we will get (-1.0) because we are passing parameter 
        // whose value is (-infinity)
        System.out.println("After implementing expm1() so the value of d2 is :" + Math.expm1(d2));

        // Here , we will get (0.0) because we are passing parameter 
        // whose value is (0.0)
        System.out.println("After implementing expm1() so the value of d3 is :" + Math.expm1(d3));

        // Here , we will get (-0.0) because we are passing parameter 
        // whose value is (-0.0)
        System.out.println("After implementing expm1() so the value of d4 is :" + Math.expm1(d4));

        // Here , we will get [(e raised to the power of 0.8) - 1] 
        // because we are passing parameter whose value is (0.8)
        System.out.println("After implementing expm1() so the value of d5 is :" + Math.expm1(d5));

        // Here , we will get [(e raised to the power of 2) - 1] 
        // because we are passing parameter whose value is (2)
        System.out.println("After implementing expm1() so the value of d6 is :" + Math.expm1(d6));
    }
}

Output

E:\Programs>javac Expm1Method.java

E:\Programs>java Expm1Method
Before implementing expm1() so the value of d1 is :Infinity
Before implementing expm1() so the value of d2 is :-Infinity
Before implementing expm1() so the value of d3 is :0.0
Before implementing expm1() so the value of d4 is :-0.0
Before implementing expm1() so the value of d5 is :0.8
Before implementing expm1() so the value of d6 is :2.0

After implementing expm1() so the value of d1 is :Infinity
After implementing expm1() so the value of d2 is :-1.0
After implementing expm1() so the value of d3 is :0.0
After implementing expm1() so the value of d4 is :-0.0
After implementing expm1() so the value of d5 is :1.2255409284924677
After implementing expm1() so the value of d6 is :6.38905609893065



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.