java中float的偏移量二进制格式
当我查看偏移二进制的维基百科页面时,我无法遵循以下句子:
然而,不同寻常的是,它不是使用“excess 2^(n-1)”,而是使用“excess 2^(n-1)-1" 这意味着反转的前导(高位)位 指数不会将指数转换为正确的二进制补码 符号。
谁能详细解释一下并给我一些例子?
when i am looking at the wikipedia page for Offset Binary, i cant follow the following sentence:
Unusually however, instead of using "excess 2^(n-1)" it uses "excess
2^(n-1)-1" which means that inverting the leading (high-order) bit of
the exponent will not convert the exponent to correct twos' complement
notation.
can anyone explain it in details and give me some examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是指数范围,允许您计算 1/Float.MAX_VALUE 和 1/Float.MIN_NORMAL,而无需为零或无穷大。如果多一个负指数和少一个正指数,(偏移量为 128)1/Float.MIN_NORMAL 将是无穷大。
浮点中的指数是偏移的,而不是简单的二补码。
例如,对于 double ,0 指数是 1023 或 0b0111111111 的 11 位值,-1 是 1022 或 0b0111111110,+1 是 1024 0b10000000000。
在二进制补码中,数字为 0 为 0b00000000000,-1 为 0b11111111111,+1 为 0b00000000001
使用偏移量的一个属性是,最大值是可能值数量的一半。即对于 11 位,范围是 -1023 到 1024,而不是 -1024 到 1023。
另一个属性是可以通过比较整数值来比较数字。
即
唯一的区别在于 NaN 和 -0.0 的处理 Double.compare(double, double) 使用的方法基于此。
This is the range of exponents which allows you to calculate 1/Float.MAX_VALUE and 1/Float.MIN_NORMAL without going to zero or Infinity. If there was one more negative exponent and one less positive exponent, (with an offset of 128) 1/Float.MIN_NORMAL would be Infinity.
The exponent in floating point is offset rather than plain two-complement.
e.g. for
double
a 0 exponent is 11-bit value for 1023 or 0b0111111111, -1 is 1022 or 0b0111111110, +1 is 1024 0b10000000000.In twos-complement, the number would be 0 is 0b00000000000, -1 is 0b11111111111, and +1 is 0b00000000001
A property of using an offset, is that the maximum is half the possible number of values. i.e. for 11 bits the range is -1023 to 1024 instead of -1024 to 1023.
Another property is that number can be compared by just comparing the integer values.
i.e.
The only difference is in the handling of NaN and -0.0 The approach Double.compare(double, double) uses is based on this.