×

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

Different Ways to Take Input from User in Java

Any information provided to a system for use is known as user input. Any responsive software or application must include user input. In Java, there are 4 different ways to...

5 minutes read.

Interface Program in Java

Interface Program in Java In the previous topic, we discussed that abstraction is possible through the interface and abstract class. An abstract class provides partial to 100% abstraction. 100 %abstraction in...

4 minutes read.

if-else Program in Java

if-else Program in Java The if-else program in Java controls which code snippet will execute. The if-else program is very basic and yet very important. Because it checks how well one...

19 minutes read.

Java Integer longValue() method

The longValue()  method of Java Integer class returns a long value for this Integer after a widening primitive conversion. Syntax public long longValue() Parameters NA Specified by This method is specified by longValue in class Number Return...

1 minute read.

Array Programs in Java

Array Programs in Java: An array is a data structure that stores similar elements in a contiguous memory location. In Java, an array is an object that stores the same...

7 minutes read.

Shift right zero Fill Operator in Java and Operator Shifting

Left shift operator ( << ) : The left shift operator is an operator which performs its action at the bits level of a binary Operator. That means when you perform...

4 minutes read.

POJO in Java

Plain old Java Object, in short, is called POJO in Java. POJO is an everyday object that is not subject to any specific limitations. We can use POJO in any Java...

3 minutes read.

Compare Two Times in Java

Definition The compareTo() function of the LocalTime class is used to compare times. The class's compareTo() method compares two LocalTime objects. Here we have two objects that have to be compared: the...

4 minutes read.

Java HashSet

HashSet implements the set interface. It uses the hash table to make the collection to store different data types. The hash set is the unordered collection of different data types....

6 minutes read.

Can Abstract Classes have Static Methods in Java

Abstract Class An abstract class in Java is one that explicitly uses the keyword "abstract" in its declaration. There are options for both non-abstract and abstract techniques (method with the body)....

4 minutes read.

Java Implements Keyword

To understand about the keyword implements we need to learn about the concept of the interfaces and inheritance in java programming languages. So let us learn about the interface and...

3 minutes read.

Dutch National Flag Problem in Java

Dutch National Flag (DNF) is a programming issue that Edsger Dijkstra put up. The white, red, and blue hues make up the Dutch flag. The goal is to haphazardly set...

6 minutes read.

Java Class Name

How to write a class name? The following considerations should be made while writing class names. The name of the current class shouldn't be based on a preset or existing class. Java keywords...

3 minutes read.

Java String

Definition A string is a series of characters. Consider an example, "Welcome" is a 7-character string. In Java, String is an unchangeable object. That is, the String is perpetual and cannot be replaced after it is created. This is the tutorial in which you...

4 minutes read.

Java Set Interface

We use set when we don't want to allow duplicate entries. All Set implementations do not allow duplicates. HashSet: This class stores its elements in hash tables. It uses the hashCode()...

3 minutes read.

How to Create an API in Java?

Introduction The API can be abbreviated as Application Programming Interface. An API is a combination of set of classes and interfaces. It is also equivalent to a simple java program. To...

12 minutes read.

Graph Problems in Java

A graph is a special type of data structure used in programming that is made up of edges connecting each set of finitely many nodes, or vertices, to each other....

14 minutes read.

Insertion Sort in Java

Insertion Sort in Java Insertion sort in Java is a simple sorting algorithm that works in the same way as we hold cards in hand. Insertion sort does the sorting element-by-element,...

3 minutes read.

Java File

Java file class implements the concept of file handling. It has several methods, such as deleting, creating, reading, and updating files. This class allows java users to perform various operations...

5 minutes read.

Java DatagramSocket and Java DatagramPacket

Datagrams TCP/IP style networking specifies a serialized, predictable, and reliable stream of data in the form of a packet. Servers and clients communicate through a reliable channel, such as TCP socket, have a dedicated...

6 minutes read.