Java Math getExponent() method with Example
Last Updated :
09 Apr, 2018
The java.lang.Math.getExponent() returns the unbiased exponent used in the representation of a double or float.
Note:
- If the argument is NaN or infinite of double or float type, then the result is (Double.MAX_EXPONENT + 1) or (Float.MAX_EXPONENT + 1).
- If the argument is zero or subnormal of double or float type, then the result is (Double.MIN_EXPONENT -1) or (Float.MIN_EXPONENT -1).
Syntax :
public static int getExponent(DataType a)
Parameter :
a : an argument of double or float type
Return :
This method returns the unbiased exponent of the argument.
import java.lang.Math;
class Gfg {
public static void main(String args[])
{
double a = 345.65 ;
double b = 1.0 / 0 ;
double c = 0 ;
System.out.println(Math.getExponent(a));
System.out.println(Math.getExponent(b));
System.out.println(Math.getExponent(c));
float d = 237 .2f;
float e = 1 .0f / 0 ;
float f = 0f;
System.out.println(Math.getExponent(d));
System.out.println(Math.getExponent(e));
System.out.println(Math.getExponent(f));
}
}
|
Output:
8
1024
-1023
7
128
-127
Share your thoughts in the comments
Please Login to comment...