简体   繁体   English

尝试表示 2^(-23) 时,无法在单精度 IEEE-754 中掌握“转换引起的错误”

[英]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.13.140.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-70.00000011920928955078 In single-precision IEEE-754, it can be constructed as follows:在单精度 IEEE-754 中,它可以构造如下:

  • The sign bit is 0符号位为0
  • The biased exponent is 104 (or 0b01101000 in binary) to account for the 127-bias, leading to -23 being the final exponent value偏置指数为104 (或二进制为0b01101000 )以说明 127 偏置,导致-23成为最终指数值
  • The mantissa's bit field is entirely composed of 0 s, its ultimate value being 1.0 when the implicit 1 -bit is accounted for尾数的位域完全由0组成,当隐含的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.000000119209289550781251.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.

相关问题 如何生成随机(IEEE-754 单精度)浮点文件? - How do I generate a file of random (IEEE-754 single-precision) floats? 将十进制转换为单精度IEEE 754 - Converting Decimal to Single-Precision IEEE 754 IEEE-754 单精度表示的最大绝对和相对误差? - Maximum absolute and relative error of IEEE-754 single precision representation? 数据类型浮点精度(IEEE 754 单精度) - Accuracy of data type float (IEEE 754 Single-precision) 将字节重新解释为C中的浮点数(IEEE 754单精度二进制) - Reinterpret bytes as float in C (IEEE 754 single-precision binary) 将IEEE-754双精度和单精度转换为十进制Java错误 - Converting IEEE-754 double and single precision to decimal Java bug 将二进制字符串转换为IEEE-754单精度-Python - Convert a binary string into IEEE-754 single precision - Python 如何将601.0转换为IEEE-754单精度 - How to convert 601.0 to IEEE-754 Single Precision 为什么 IEEE754 单精度浮点数只有 7 位精度? - Why IEEE754 single-precision float has only 7 digit precision? 如何检查是否使用了 IEEE 754 单精度(32 位)浮点表示法? - How to check that IEEE 754 single-precision (32-bit) floating-point representation is used?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM