java - java中如何检查一个数的指数

标签 java

我想检查我的程序中生成的数字的指数。 (当我打印时,它们的生成方式类似于 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 位),然后以这种方式检查指数值。

此链接将有助于解码:IEEE754 double FP format - exponent encoding

关于java - java中如何检查一个数的指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5495891/

相关文章:

java - String#replace 在我的方法中不起作用

java - 为什么以及何时在 Java 中使用骨架实现

java OpenCV 找到 k 最近邻 c++ 到 java 的转换

java - Android ExpandableList onChildClickListener 在 Fragment 中不起作用

java - jmeter 测试因内存不足错误而失败

java - 在作为 jar/war 运行的 Spring Boot 应用程序中,JAXB 解码非常慢

java - 如何将 NetBeans 平台源代码包含到模块依赖项中

java - 修改 katharsis json 响应

java - 建立在字节数组上的位 vector ——理解位操作

java - 将参数从 Activity 传递到另一个 Activity Fragments