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