What is the Math.getExponent() method in Java?
The static method getExponent() is used to get the unbiased exponent used in the demonstration of a number (double or float).
Syntax
For double-type values:
static int getExponent(double x)
For floating-point values:
static int getExponent(float x)
Parameters
x: This is an argument value of either double or float type.
Return value
The getExponent() function from the math library returns the unbiased exponent of the argument x.
Special cases
-
The result will be
Double.MAX_EXPONENT + 1orFloat.MAX_EXPONENT + 1when the argument value isinfiniteorNaN. -
The result will be
Double.MIN_EXPONENT -1orFloat.MIN_EXPONENT - 1when the argument value issubnormalorzero.
Double.MAX_EXPONENT= 1023Double.MIN_EXPONENT= -1022Float.MAX_EXPONENT= 127Float.MIN_EXPONENT= -126
Code
In the code snippet below:
- Case 1: When the argument value is a positive number, it will show an unbiased exponent.
- Case 2: When an argument is of infinite value, then the result will be
Double.MAX_EXPONENT + 1orFloat.MAX_EXPONENT + 1. - Case 3: When an argument is zero, then the result will be
Double.MIN_EXPONENT -1orFloat.MIN_EXPONENT - 1.
import java.lang.Math;// Main classclass EdPresso {public static void main( String args[] ) {double num1=10;float num2=1024;System.out.println("Double type num1: " + Math.getExponent(num1));System.out.println("Float type num2: " + Math.getExponent(num2));}}