Java Math.getExponent() method returns unbiased exponent used in the representation of the argument. This method can accept double and float arguments.
public class JavaExample
{
public static void main(String[] args)
{
double x = Double.POSITIVE_INFINITY;
// Returns Double.MAX_EXPONENT+1
System.out.println(Math.getExponent(x));
}
}
Output:
1024
Syntax of Math.getExponent() method
public static int getExponent(double d) public static int getExponent(float f)
getExponent() Description
It returns the unbiased exponent used in the representation of arguments d (for double argument variant) and f (for float argument variant of this method).
getExponent() Parameters
- d: A double value
- f: A float value
getExponent() Return Value
- Returns unbiased exponent of the argument.
- If the argument
dis zero, then it returnsDouble.MIN_EXPONENT - 1. - If the argument
fis zero, then it returnsFloat.MIN_EXPONENT - 1. - If the argument
dis NaN or infinite, then it returnsDouble.MAX_EXPONENT - 1. - If the argument
fis NaN or infinite, then it returnsFloat.MAX_EXPONENT - 1.
Example 1
public class JavaExample
{
public static void main(String[] args)
{
double d = 101.11;
float f = 12.55f;
System.out.println(Math.getExponent(d));
System.out.println(Math.getExponent(f));
}
}
Output:

Example 2
public class JavaExample
{
public static void main(String[] args)
{
double d = Double.NaN;
float f = 0.0f;
System.out.println(Math.getExponent(d));
System.out.println(Math.getExponent(f));
}
}
Output:

Example 3
public class JavaExample
{
public static void main(String[] args)
{
double d = Double.MAX_VALUE;
float f = Float.POSITIVE_INFINITY;
System.out.println(Math.getExponent(d));
System.out.println(Math.getExponent(f));
}
}
Output:
