Home » Java programming language

Java StrictMath exp() method with example

StrictMath Class exp() method: Here, we are going to learn about the exp() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 25, 2019

StrictMath Class exp() method

  • exp() method is available in java.lang package.
  • exp() method is used to return the exponential of the given number in the method or other words it is used to calculate the e raised to the power of the given argument. Here, exp stands for exponentiation.
  • exp() method is a static method so it is accessible with the class name and if we try to access the method with the class object then also we will not get an error.
  • exp() method does not throw any exception.

Syntax:

    public static double exp(double d);

Parameter(s):

  • double d – represents the double type value whose exponential value to be found.

Return value:

The return type of this method is double – it returns exponential value of the given parameter.

Note:

  • If we pass NaN as an argument, method returns the same value (NaN).
  • If we pass a positive infinity, method returns the same (i.e. positive infinity).
  • If we pass a negative infinity, method returns 0.0.

Example:

// Java program to demonstrate the example
// of exp(double d) method of StrictMath Class.

public class Exp {
    public static void main(String[] args) {
        // variable declarations
        double d1 = 7.0 / 0.0;
        double d2 = -7.0 / 0.0;
        double d3 = 0.8;
        double d4 = 2;

        // Display previous value of d1,d2,d3 and d4 
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);

        // Here , we will get (Infinity) because we are
        // passing parameter whose value is (infinity)
        System.out.println("StrictMath.exp(d1): " + StrictMath.exp(d1));

        // Here , we will get (0.0) because we are
        // passing parameter whose value is (-infinity)
        System.out.println("StrictMath.exp(d2): " + StrictMath.exp(d2));

        // Here , we will get (e raised to the power of 0.8) because we are
        // passing parameter whose value is (0.8)
        System.out.println("StrictMath.exp(d3): " + StrictMath.exp(d3));

        // Here , we will get ( e raised to the power of 2) because we are
        // passing parameter whose value is (2)
        System.out.println("StrictMath.exp(d4): " + StrictMath.exp(d4));
    }
}

Output

d1: Infinity
d2: -Infinity
d3: 0.8
d4: 2.0
StrictMath.exp(d1): Infinity
StrictMath.exp(d2): 0.0
StrictMath.exp(d3): 2.225540928492468
StrictMath.exp(d4): 7.38905609893065


Comments and Discussions!

Load comments ↻





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