📅  最后修改于: 2023-12-03 14:42:15.321000             🧑  作者: Mango
Java Math类中的getExponent()
方法返回一个double
参数的指数。如果参数是NaN或无穷大,则结果为Double.MAX_VALUE或Double.MIN_VALUE。
public static int getExponent(double d)
参数:
d
:要计算指数的double值返回值:
public class MathGetExponentExample {
public static void main(String[] args) {
double positiveInfinity = Double.POSITIVE_INFINITY;
double negativeInfinity = Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
double zero = 0;
double number = 123.456;
System.out.println("Positive Infinity Exponent: " + Math.getExponent(positiveInfinity));
System.out.println("Negative Infinity Exponent: " + Math.getExponent(negativeInfinity));
System.out.println("NaN Exponent: " + Math.getExponent(nan));
System.out.println("Zero Exponent: " + Math.getExponent(zero));
System.out.println("Number Exponent: " + Math.getExponent(number));
}
}
输出结果:
Positive Infinity Exponent: 1024
Negative Infinity Exponent: -1023
NaN Exponent: 2047
Zero Exponent: -1074
Number Exponent: 6
上面的代码演示了getExponent()
方法对不同类型的值返回的指数值。
Integer.MAX_VALUE
(即1024
)。Integer.MIN_VALUE
(即-1023
)。NaN
时,指数值为Integer.MAX_VALUE
+1(即2047
)。0
时,指数值为Double.MIN_VALUE
的指数值(即-1074
)。