在加法之后舍入浮点数(保护,粘性和圆位) [英] Rounding Floating Point Numbers after addition (guard, sticky, and round bits)

查看:3434
本文介绍了在加法之后舍入浮点数(保护,粘性和圆位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没能在网络上的任何地方找到一个很好的解释,所以我希望这里有人能为我解释。

我想添加两个二进制数:1.001 2 * 2 2

1.010,0000,0000,0000,0000,0011 2 * 2 1



我可以添加他们没有问题,我取得了下面的结果,解规范的第一个数字,添加两个,并重新正常化他们。




1.1100,0000,0000,0000,0000,0011 2 * 2 2
$ b $ p

问题是,这个数字不适合单精度IEEE 754格式,不会截断或舍入一位。我的任务是要求我们把这个数字转换成单精度的IEEE 754格式(这也是通常没有问题,我可以这么做)。它要求我们首先用警卫,圆形和粘性位来做,然后重复这些位。不过,我不确定这些位是如何帮助四舍五入的。然而,假设我只是截断了最后一个LSB​​,但是如果我不这样做的话,还是不加防护的,圆的和粘性的。单精度意味着尾数持有23位(假设32位架构),加上一个隐藏的。因此第一个从尾数消失。

接下来是确定G和R位或Guard和Round位。

保护位是尾数的0位之后的两位中的第一位,将被截断。

圆位是尾数位的第二位。这里的保护位是1,并且由于没有其他位存在,所以轮位为零。

粘性位也是零,因为在位的右边没有一个。因此,我们有GRS或100.



根据使用的书籍或处理器,这通常意味着最接近的偶数。在这种情况下,由于LSB(最低有效位)为1,因此尾数将舍入为1100,0000,0000,0000,0000,010。

I haven't been able to find a good explanation of this anywhere on the web yet, so I'm hoping somebody here can explain it for me.

I want to add two binary numbers by hand:

1.0012 * 22
1.010,0000,0000,0000,0000,00112 * 21

I can add them no problem, I get the following result after de-normalizing the first number, adding the two, and re-normalizing them.

1.1100,0000,0000,0000,0000,00112 * 22

The issue is, that number will not fit into single-precision IEEE 754 format without truncating or rounding one bit. My assignment asks that we put this number into single-precision IEEE 754 format (which again, is normally no problem, I can do that easy). It asks us to do so first with guard, round, and sticky bits and then repeat without these bits. However, I'm not exactly sure how these bits help with rounding. I would assume that I would just truncate the last LSB if I were to do this without guard, round, and sticky bits, however.

解决方案

Single precision means the mantissa holds 23 bits (assuming 32 bit architecture), plus a hidden one. Therefore the first one disappears from the mantissa.

Next is to determine the G and R bits or Guard and Round bit.

The Guard bit is the first of two bits past the 0 bit of the mantissa that will be cutoff.

The round bit is the second bit after the o bit of the mantissa. The guard bit here is 1 and the round bit is zero since no other bit is present.

The sticky bit is also zero because there are no ones to the right of the round bit. Therefore we have GRS or 100.

Depending on the book or processor being used this normally means round to the nearest even number. In this case since the LSB (least significant bit) is 1 the number will be rounded up to 1100,0000,0000,0000,0000,010 for the mantissa.

这篇关于在加法之后舍入浮点数(保护,粘性和圆位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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