📅  最后修改于: 2023-12-03 15:01:57.072000             🧑  作者: Mango
getExponent()
方法是 Java 中 StrictMath
类中的一个静态方法,用于获取浮点数的阶码。
public static int getExponent(double d)
d
:需要获取阶码的浮点数。public class GetExponentExample {
public static void main(String[] args) {
double num1 = 12.34;
double num2 = 1.23e-5;
double num3 = -56.78;
double num4 = Double.NaN;
double num5 = Double.POSITIVE_INFINITY;
double num6 = Double.NEGATIVE_INFINITY;
System.out.println("getExponent(" + num1 + ") = " + StrictMath.getExponent(num1));
System.out.println("getExponent(" + num2 + ") = " + StrictMath.getExponent(num2));
System.out.println("getExponent(" + num3 + ") = " + StrictMath.getExponent(num3));
System.out.println("getExponent(" + num4 + ") = " + StrictMath.getExponent(num4));
System.out.println("getExponent(" + num5 + ") = " + StrictMath.getExponent(num5));
System.out.println("getExponent(" + num6 + ") = " + StrictMath.getExponent(num6));
}
}
输出:
getExponent(12.34) = 3
getExponent(1.23E-5) = -17
getExponent(-56.78) = 6
getExponent(NaN) = 1024
getExponent(Infinity) = 1024
getExponent(-Infinity) = 1024
以上例子中: