java.lang.Math.getExponent()返回在double或float表示中使用的无偏 index 。注意:
如果参数为NaN或double或float类型的无限,则结果为(Double.MAX_EXPONENT +1)或(Float.MAX_EXPONENT +1)。
如果参数为零或double或float类型的子范数,则结果为(Double.MIN_EXPONENT -1)或(Float.MIN_EXPONENT -1)。
用法:
public static int getExponent(DataType a)
参数:
a:an argument of double or float type
返回:
This method returns the unbiased exponent of the argument.
// Java program to demonstrate working
// of java.lang.Math.getExponent() method
import java.lang.Math;
class Gfg {
// driver code
public static void main(String args[])
{
double a = 345.65;
double b = 1.0 / 0;
double c = 0;
// Input double value
// Output unbiased exponent of it
System.out.println(Math.getExponent(a));
// Input Infinity
// Output (Double.MAX_EXPONENT + 1)
System.out.println(Math.getExponent(b));
// Input Zero
// Output (Double.MIN_EXPONENT - 1)
System.out.println(Math.getExponent(c));
float d = 237.2f;
float e = 1.0f / 0;
float f = 0f;
// Input float value
// Output unbiased exponent of it
System.out.println(Math.getExponent(d));
// Input Infinity
// Output (Float.MAX_EXPONENT + 1)
System.out.println(Math.getExponent(e));
// Input Zero
// Output (Float.MIN_EXPONENT - 1)
System.out.println(Math.getExponent(f));
}
}
输出:
8
1024
-1023
7
128
-127