了解这些浮点数如何工作? [英] Understanding how these floating point numbers work?

查看:85
本文介绍了了解这些浮点数如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点难以理解浮点数的工作原理.具体在下面的以下表示中(纠正我的错误):

I'm having a little difficulty understanding how floating point numbers work. Specifically in the following representations below (correct my mistakes):

  1. 表示0:用指数位中的全0位表示(单精度为8,双精度为11).如果我的指数位中全为零,即使我的尾数不全为零,我仍然能够表示零吗?

  1. Representing 0: this is represented by a full 0 bits in the exponent bits (8 in single precision and 11 in double precision). If I have all zeros in the exponent bits, will I still be able to represent zero even if my mantissa is not all zero?

维基百科显示零由(−1)signbit×2 ^ {− 126}×0表示.significandbits为什么当我们能达到的最低指数值为2 ^ {-126}时为2 ^ {-126}. -127}代替?

Wikipedia shows that zero is represented by (−1)signbit×2^{−126}× 0.significandbits Why is it 2^{-126} when the lowest exponent value we can reach is 2^{-127} instead?

代表反常数:我想反常数也以这种格式表示:(-1)signbit×2 ^ {-126}×0.significandbits.它们用于表示低于最小正常数的值.我猜这是2 ^ {-127},但是如果非正规数的表示形式是这样,非正规数是否仍会代表比常规数大的值?

Representing denormal numbers: I suppose denormal numbers are represented as this format as well: (−1)signbit×2^{−126}× 0.significandbits. They are used to represent values lower than the smallest normal number. I'm guessing this is 2^{-127}, but if the representation for denormal numbers is as such, wouldn't denormal numbers still represent larger values than normal ones?

归一化数:(-1)signbit×2 ^ {exponentbits−127}×1.significandbits.我假设指数位的实际表示形式是0到255,因为它们不以两种补码形式表示.

normalised numbers: (−1)signbit×2^{exponentbits−127}× 1.significandbits. I'm supposing the actual representation of the exponentbits is in terms of 0 to 255, as they don't represent in two complements form.

正负无穷大,由指数位中的完整1位表示.同样,如果我们使用这种表示形式来表示无穷大,那么非零尾数是否重要?

plus/minus infinity represented by a full 1 bits in the exponent bits. Again, does a non-zero mantissa matter if we use this representation to signify infinity?

推荐答案

根据IEEE 754-2008:

Per IEEE 754-2008:

  • NaN::如果指数字段为全1,而有效位数不为零,则浮点数据为NaN,而不考虑符号字段.优选地,QNaN具有有效数字段1的前导位,而信令NaN具有0,但这不是必需的.
  • 无穷大:如果指数字段为全1,而有效字段为零,则基准为(−1) s •∞ ,其中 s 是符号字段. (,如果符号为0,则为+∞;如果符号为1,则为-∞.)
  • 普通:如果指数字段既不是全零也不是全零,则基准为(-1) s •(1 + f •2 q )•2 e - bias ,其中 s 是符号字段, f 是有效字段, q 是有效字段中的位数, e 是指数字段,而 bias 是指数偏差(对于32位浮点数为127).
  • 次正态:如果指数字段全为零,而有效位数不是,则数据为(-1) s • (0 + f •2 q )•2 1- bias .请注意与正常值的两个区别:0被添加到有效位数,而不是1,并且1被用作指数(在减去 bias 之前).这意味着次法线与最小法线具有相同的指数,但是通过减小有效位数而减小.
  • 零:如果指数字段全为零,而有效数字段也全为零,则基准为(-1) s •0.(请注意,IEEE 754区分+0和−0.)
  • NaN: If the exponent field is all ones and the significand field is not zero, the floating-point datum is a NaN, regardless of the sign field. Preferably, a QNaN has the leading bit of the significand field 1 and a signaling NaN has 0, but this is not required.
  • Infinite: If the exponent field is all ones and the significand field is zero, the datum is (−1)s • ∞, where s is the sign field. (I.e., +∞ if the sign is 0 and −∞ if the sign is 1.)
  • Normal: If the exponent field is neither all zeros nor all ones, the datum is (−1)s • (1 + f • 2q) • 2e - bias, where s is the sign field, f is the significand field, q is the number of bits in the significand field, e is the exponent field, and bias is the exponent bias (127 for 32-bit floating-point).
  • Subnormal: If the exponent field is all zeros, and the significand field is not, the datum is (−1)s • (0 + f • 2q) • 21 - bias. Note the two differences from normal: 0 is added to the significand instead of 1, and 1 is used for the exponent (before subtracting bias). This means subnormals have the same exponent as the smallest normals but are decreased by reducing the significand.
  • Zero: If the exponent field is all zeroes, and the significand field is also all zeros, the datum is (−1)s • 0. (Note that IEEE 754 distinguishes +0 and −0.)

与次常态配合使用的指数是1而不是0,因此数字从1.000…000•2 1-127 变为(次正态)0.111…111•2 1 −127 .如果使用0,则将跳至0.0111…1111•2 1−127 .

The exponent used with subnormals is 1 rather than 0 so that the numbers change from (normal) 1.000…000•21−127 to (subnormal) 0.111…111•21−127. If 0 were used, there would be a jump to 0.0111…1111•21−127.

子法线值的公式也适用于零.因此,实际上不需要在上方单独列出零.

The formula for the values of subnormals works for zeros too. So zeros do not actually need to be listed separately above.

这篇关于了解这些浮点数如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆