我想检查我的程序中生成的数字的指数。 (当我打印时,它们的生成方式类似于 2.333E-4
)。我想检查哪些数字的指数小于 E-4
,需要乘以 10 来增加指数,直到达到 E-4
。
有什么想法可以实现这一目标吗?即使有人可以告诉我如何提取指数,也会很有帮助。
最佳答案
您可以使用Java docs: Double.doubleToRawLongBits
Double.doubleToRawLongBits
public static long doubleToRawLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, preserving Not-a-Number (NaN) values.
Bit 63 (the bit that is selected by the mask 0x8000000000000000L) represents the sign of the floating-point number.
Bits 62-52 (the bits that are selected by the mask 0x7ff0000000000000L) represent the exponent.
Bits 51-0 (the bits that are selected by the mask 0x000fffffffffffffL) represent the significand (sometimes called the mantissa) of the floating-point number.
因此,您可以将 double 值转换为 long,向右移动 13*4(13 个十六进制数字 = 13*4 位),然后以这种方式检查指数值。
关于java - java中如何检查一个数的指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5495891/