×

Java Math getExponent() Method

The getExponent() method of Math class returns the unbiased exponent of the argument.

Syntax:

public static int getExponent (double d)

Parameters:

The parameter ‘d’ represents the double value.

Return Value:

The getExponent () method returns the unbiased exponent used in the representation of a double.

Special cases are as follows:

  • It returns Double.MAX_EXPONENT+1, if the argument is NaN or infinite.
  • It returns Double.MIN_EXPONENT-1, if the argument is zero or subnormal.

Example 1:

public class JavaMathGetExponentExample1 {
    public static void main(String[] args) {
        double a = 20;
        //returns the unbiased exponent of the argument
        System.out.println(Math.getExponent(a));
    }
}

Output:

4

Example 2:

public class JavaMathGetExponentExample2 {
    public static void main(String[] args) {
        double x=0.0d;
        //It returns Double.MIN_EXPONENT-1, if the argument is zero or subnormal.
        System.out.println(" Unbiased exponent of "+ x+" =
"+Math.getExponent(x));
    }
}

Output:

Unbiased exponent of 0.0 = -1023

Example 3:

public class JavaMathGetExponentExample3 {
    public static void main(String[] args) {
        float x=0.0f/0.0f;
        //It returns Double.MAX_EXPONENT+1, if the argument is NaN or infinite
        System.out.println(" Unbiased exponent of "+ x+" =
"+Math.getExponent(x));
    }
}

Output:

Unbiased exponent of NaN = 128

Example 4:

public class JavaMathGetExponentExample4 {
    public static void main(String[] args) {
        float x=8.0f/0.0f;
        //It returns Double.MAX_EXPONENT+1, if the argument is NaN or infinite
        System.out.println(" Unbiased exponent of "+ x+" =
"+Math.getExponent(x));
    }
}

Output:

Unbiased exponent of Infinity = 128

Related Topics

Java protected vs private

Java : Java is a pure object oriented language. It was introduced by James Gosling in the year 1995. The first public implementation of java was done by sun micro systems...

3 minutes read.

Java String hashCode() method

Java String hashCode() method returns hash code for current String. hash code for string object is computed as s[0]*31^(n - 1) + s[1]*31^(n - 2) + ... + s[n - 1] Using int...

2 minutes read.

Java Maven Silicon

Maven is a build automation tool that is mostly used for Java applications. It allows you to manage the build, reporting, and documentation of a project from the central location. Maven provides...

4 minutes read.

Java Byte Code

Java byte code is really a powerful mechanism which makes Java a portable and platform-independent programming language. There are two software components which go along and make this byte code...

3 minutes read.

Java vs DotNET

Before understanding the differences between DotNET and Java, one must know about Java and DotNET. Java Java is a general-purpose programming language that is class-based and object-oriented, with minimal implementation dependencies. Regardless of...

9 minutes read.

Java Integer toBinaryString() method

The toBinaryString() method of Java Integer class returns a string representing the specified int argument as an unsigned integer in base 2. Syntax public static String toBinaryString (int  i)  Parameters The parameter ‘i’ represents...

1 minute read.

Hashtable in Java

Hashtable in Java The Hashtable class implements the Map interface and extends the Dictionary class. It implements a hash table which shows the key-value relation, i.e., it maps the keys to the values....

9 minutes read.

Loose Coupling in Java

Loosely coupling mechanism in java means one reference of a variable capable of holding multiple implementation class memory is called loosely coupling. Or in other words, one interface reference variable...

3 minutes read.

Java String Interview Questions

Java String Interview Questions String is the most common and important discussed topics in a Java interview. In Java interview interviewer generally asked three to four questions based on String concept....

16 minutes read.

Get year from date in Java

The getYear() method of the Java date class returns a number calculated by deducting 1900 from the year that contains or starts with the instant in time represented by this...

4 minutes read.

Java Math getExponent() Method

The getExponent() method of Math class returns the unbiased exponent of the argument. Syntax: public static int getExponent (double d) Parameters: The parameter ‘d’ represents the double value. Return Value: The getExponent () method returns the...

1 minute read.

Producer Consumer Problem in Java Using Synchronized Block

The producer-consumer dilemma is a well-known instance of a multi-process synchronization issue in computing. Two processes—the producer and the consumer—are described in the issue, and they share a single, fixed-size...

4 minutes read.

Java FileNotFoundException

FileNotFoundException is another exception class accessible in the java.io bundle. The exemption happens when we attempt to get to that document which isn't accessible in the framework. It is a checked...

5 minutes read.

Stable Marriage Problem in Java

Given N men and N women, the Stable Marriage Problem asks you to match up the men and women in such a way that there are never any two people...

6 minutes read.

String Handling Method in 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...

4 minutes read.

Java String charAt() method

It returns the char value present in the string at the specified index. Here, index value can not be greater than length() -1. Syntax: public char charAt (int index) Parmeters It accepts only...

3 minutes read.

Java Integer sum() method

The sum() method of Java Integer class add the two specified integers values. It returns the same result as given by + operator. Syntax public static int sum (int a, int b)  Parameters The...

1 minute read.

Sleep Time in Java

Sleep is amethod in java that is related to thread class and it is a concept of multithreading and is used to stop the execution of the current thread a...

4 minutes read.

Switch Case Program in Java

Switch Case Program in Java The switch case program in Java controls which code snippet gets executed on the basis of the value of the expression mentioned in the switch statement....

22 minutes read.

Java Else Keyword

The else statement specifies a section of Java code that will run if an if statement's condition is false.The following conditional statements can be used in Java:To provide a block...

3 minutes read.