Java.lang Package Classes

Java Math - getExponent() Method



The java.lang.Math.getExponent() method returns the unbiased exponent used in the representation of argument. In special cases it returns the following:

  • If the argument is NaN or infinite, then the result is (Float.MAX_EXPONENT + 1).
  • If the argument is zero or subnormal, then the result is (Float.MAX_EXPONENT + 1).

Syntax

public static int getExponent(float f)

Parameters

f Specify a float value.

Return Value

Returns the unbiased exponent used in the representation of argument.

Exception

NA.

Example:

In the example below, getExponent() method returns the unbiased exponent used in the representation of argument.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.getExponent(10.5f)); 
  System.out.println(Math.getExponent(25.0f)); 
  System.out.println(Math.getExponent(600.78f)); 
  System.out.println(Math.getExponent(1050.0f));     
 }
}

The output of the above code will be:

3
4
9
10

❮ Java.lang - Math