VOOZH about

URL: https://www.geeksforgeeks.org/java/java-math-getexponent-method/

⇱ Java Math getExponent() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Math getExponent() Method

Last Updated : 13 May, 2025

In Java, the Math.getExponent() method returns the exponent of the floating-point number in its binary scientific notation. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.

Note: This method works withboth double and float types also, the number is represented in binary format, and this method gives us the exponent part of the binary representation.

Special Cases:

  • If the argument is NaN or infinity, then the result will be Double.MAX_EXPONENT + 1 or Float.MAX_EXPONENT + 1.
  • If the argument is zero or a very small number, then the result will be Double.MAX_EXPONENT - 1 or Float.MAX_EXPONENT - 1.

These special cases make sure that the Math.getExponent() methods work correctly.

Syntax of getExponent() Method

public static int getExponent(double d)

  • Parameter: This method takes a single parameter d, of type double value whose exponent is to be returned.
  • Return Type: This method returns the exponent part of a floating point number as an integer.

Now, we are going to discuss some examples for better understanding.


Examples of Java Math getExponent() Method

Example 1: In this example, we will see the basic usage of getExponent() method.


Output
Exponent of 12345.67: 13
Exponent of 1.23E-7: -23
Exponent of 1000000.0: 19


Example 2: In this example, we will see how getExponent() method handles NaN and Infinity.


Output
Exponent of NaN: 1024
Exponent of Infinity: 1024

Explanation: Here, we are handling the cases like NaN and Infinity. For NaN it is returning 1024 and for Infinity it is returning 1024.

Important Points:

  • This method is very useful when we have to deal with binary representation of floating point numbers.
  • This method also used when we have to compare large and small numbers in scientific computations.
  • It works for both float and double values.
Comment
Article Tags: