Java Tutorial Java Advanced Java References

Java Math - getExponent() Method



The Java getExponent() method returns the unbiased exponent used in the representation of argument. The method can be overloaded and it can take float and double arguments. In special cases it returns the following:

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

Syntax

public static int getExponent(float a)
public static int getExponent(double a)

Parameters

a Specify a 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.

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

The output of the above code will be:

3
4
9
10

❮ Java Math Methods