Home » Java programming language

Java Math Class static int getExponent(double d) with example

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

Math Class static int getExponent(double d)

  • This method is available in java.lang package.
  • This method is used to return the unbiased exponent used in the denotation of the given argument(i.e. the argument is of double type).
  • 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 unbiased exponent of the given argument and the argument value is of double type.
  • In this method, we pass only one parameter as an argument in the method of Math class.
  • This method does not throw any exception.
  • This is an overloaded method so two versions of this method is available one is of double type argument and other is float type argument but here we have discussed double type argument.

Syntax:

    public static int getExponent(double d){
    }

Parameter(s):

double d – A double value whose unbiased exponent to be found.

Note:

  • If we pass "NaN", it returns Double.MAX_EXPONENT +1.
  • If we pass a positive or negative infinity, it returns Double.MAX_EXPONENT.
  • If we pass zero (-0 or 0), it returns Double.MIN_EXPONENT - 1.

Return value:

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

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

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

public class GetExponentMethod {
    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 = 12485.2;

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

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

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

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

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

        // Here , we will get unbiased exponent because we are 
        // passing parameter whose value is (12485.2)
        System.out.println("After implementing getExponent() so the value of d5 is :" + Math.getExponent(d5));
    }
}

Output

E:\Programs>javac GetExponentMethod.java

E:\Programs>java GetExponentMethod
Before implementing getExponent() so the value of d1 is :Infinity
Before implementing getExponent() so the value of d2 is :-Infinity
Before implementing getExponent() so the value of d3 is :0.0
Before implementing getExponent() so the value of d4 is :-0.0
Before implementing getExponent() so the value of d5 is :12485.2

After implementing getExponent() so the value of d1 is :1024
After implementing getExponent() so the value of d2 is :1024
After implementing getExponent() so the value of d3 is :-1023
After implementing getExponent () so the value of d4 is :-1023
After implementing getExponent() so the value of d5 is :13





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.