当尾数大于23位时,行为未知?

huangapple go评论53阅读模式
英文:

Unknown behaviour when mantissa is larger than 23 bits?

问题

为什么IEEE-754中的-673.4以10结尾而不是01?

符号位为1。

转换为二进制后是:1010100001.01100110011001100110011001100110...

指数为136=10001000

所以完整的数应该是:1 10001000 01010000101100110011001

但是计算器得出的是:1 10001000 01010000101100110011010

那么为什么最后两位发生了变化,以及背后的算法是什么(我如何计算它们何时发生变化)?

英文:

Why does -673.4 in IEEE-754 end with 10 and not 01?

Sign bit is 1.

Converted to binary it is: 1010100001.01100110011001100110011001100110...

Exponent is 136=10001000

So shouldn't full number be: 1 10001000 01010000101100110011001

Instead by calculators I get: 1 10001000 01010000101100110011010

So why did last two bits change, and what is algorithm behind it (how can I calculate how and when do they change)?

答案1

得分: 3

计算器给出的数字转换回十进制为-673.4000244140625,高出 24.4 百万分之一。

您提出的“正确”编码转换回为-673.3999633789062,低了 36.6 百万分之一。

它们都非常接近您想要的数字,但意外的那个更接近。

IEEE 四舍五入规则通常会四舍五入到最接近的数字,尽管您所想象的“截断”或朝零方向舍入的方案也在一些设备或应用中被定义和使用。

英文:

The number given by calculators converts back to decimal as -673.4000244140625, or 24.4 millionths too high.

The number you propose as the "proper" encoding converts back as -673.3999633789062, or 36.6 millionths too low.

They're both very close to the number you wanted, but the uexpected one is marginally closer.

IEEE rounding usually rounds to the nearest number, although the scheme you imagined, "truncation" or round towards zero, is also defined and used in some devices or applications.

huangapple
  • 本文由 发表于 2023年6月19日 16:51:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76505062.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定