[英]Trouble grasping "error due to conversion" in single-precision IEEE-754 when attempting to represent 2^(-23)
Let me preface the question by saying that I understand why values such as 0.1
, 3.14
, 0.2
, and other values not composable of combinations of powers of two are ultimately unrepresentable by IEEE-754 formats, and that they may only be approximated as best as the precision allows.让我先说这个问题,我理解为什么诸如
0.1
、 3.14
、 0.2
之类的值和其他不能由两个幂的组合组合的值最终无法用 IEEE-754 格式表示,并且它们可能只能近似为最佳精度允许。
What I am having trouble understanding is why attempting to represent the value 2 -23 results in a slight margin of error.我无法理解的是为什么尝试表示值2 -23会导致轻微的误差。
2 -23 is exactly equal to 1.1920928955078e-7
, or 0.00000011920928955078
. 2 -23正好等于
1.1920928955078e-7
或0.00000011920928955078
。 In single-precision IEEE-754, it can be constructed as follows:在单精度 IEEE-754 中,它可以构造如下:
0
0
104
(or 0b01101000
in binary) to account for the 127-bias, leading to -23
being the final exponent value104
(或二进制为0b01101000
)以说明 127 偏置,导致-23
成为最终指数值0
s, its ultimate value being 1.0
when the implicit 1
-bit is accounted for0
组成,当隐含的1
位被计算在内时,其最终值为1.0
However, storing this particular bit sequence in memory and printing it out in decimal notation, with 25 digits of precision past the decimal point results in the following:然而,将这个特定的位序列存储在 memory 中并以十进制表示法打印出来,小数点后有 25 位精度,结果如下:
0.0000001192092895507812500
^
|
margin of error starts here
This value contains an error of exactly 1.25e-21
.该值恰好包含
1.25e-21
的错误。 On this interactive website , this error value is referred to as an " Error due to conversion ".在此交互式网站上,此错误值称为“转换导致的错误”。
I am having trouble grasping this - because I understand, for example, why a value such as +3.14
cannot be exactly represented by a single-precision bitfield.我很难理解这一点——因为我理解,例如,为什么像
+3.14
这样的值不能用单精度位域精确表示。 No combination of negative powers of two in the mantissa scaled by the value in the exponent can exactly represent 3.14
, so the next closest approximation is chosen.由指数中的值缩放的尾数中两个负幂的组合不能精确表示
3.14
,因此选择下一个最接近的近似值。 Thus an "error due to conversion" is expected.因此,预计会出现“由于转换而导致的错误”。 Contrary to that, the value 2 -23 is able to be stored exactly in a single-precision bitfield, yet when converted back to a decimal notation, an error appears.
与此相反,值2 -23可以准确地存储在单精度位域中,但是当转换回十进制表示法时,会出现错误。
There's clearly some sort of misunderstanding on my part, but I can't figure out where exactly.显然我有某种误解,但我无法弄清楚到底在哪里。
2 -23 is in fact not equal to exactly 1.1920928955078e-7
. 2 -23实际上并不完全等于
1.1920928955078e-7
。
The software I was using to perform the calculation was truncating the result three digits short... The exact value of 2 -23 is precisely 0.00000011920928955078125
, or 1.1920928955078125e-7
, which is the output I was observing before, making it correct, with no margin of error whatsoever.我用来执行计算的软件将结果截断了三位数字...... 2 -23的精确值恰好是
0.00000011920928955078125
或1.1920928955078125e-7
,这是我之前观察到的 output ,使其正确,没有任何误差。
It is also worth nothing that the website truncates the decimal representation of the mantissa a few digits early, making by-hand calculations (ie multiplying the mantissa with the sign bit and 2 exponent ) seem incorrect (or at least slightly off) when they are in fact not.同样毫无意义的是,该网站提前将尾数的十进制表示形式截断了几位,使得手工计算(即,将尾数与符号位和 2指数相乘)看起来不正确(或至少略有偏差),当它们是事实上不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.