如何即使浮点数轮来执行 [英] How to perform round to even with floating point numbers
问题描述
在关于IEEE-754单precision浮点,你怎么执行就近舍,那里的联系轮所需的位置最近,即使数字(默认是迄今为止最常用的模式)<? / p>
基本上我有看守位,轮位和粘滞位。
因此,如果我们形成这些入载体,并称之为遗传资源,则遵循以下规则:
- 如果
G = 0
,本轮下跌(什么都不做) - 如果
G = 1
和RS == 10
或RS == 01
,圆(加一个尾数) - 如果
GSR = 111
,轮甚至
所以,我不知道如何进行舍入到最近。任何帮助是极大的AP preciated。
只是为了确保我们在同一页上,研究
随之而来的和取值
可以被认为是最不显著位,因为它的价值部分重新presents已在计算被截断的甚至更少显著比特。这三个位仅用于同时操作的方式计算和之前或计算之后不存储在浮点变量
这是你应该为了圆结果使用最接近的偶数做什么研究
和取值
:
GRS - 行动结果
0XX - 本轮下跌=什么也不做(X指任何位值0或1)结果
100 - 这是一个领带:圆了,如果尾数的位之前的
101 - 围捕结果
110 - 围捕结果
111 - 围捕
四舍五入是通过添加1在尾数上最显著比特位尾数刚
在平局的情况下,你加1的尾数如果尾数是奇数,你加什么,如果它是偶数。这是什么使得四舍五入为最接近的偶数值的结果。
In regards to IEEE-754 single precision floating point, how do you perform round to nearest, where ties round to the nearest even digit in the required position (the default and by far the most common mode)?
Basically I have the guard bit, round bit, and stick bit. So if we form those into a vector and call it GRS, then the following rules apply:
- If
G = 0
, round down (do nothing) - If
G = 1
, andRS == 10
orRS == 01
, round up (add one to mantissa) - if
GSR = 111
, round to even
So I am not sure how to perform the round to nearest. Any help is greatly appreciated.
Just to make sure we're on the same page, G
is the most significant bit of the three, R
comes next and S
can be thought of as the least significant bit because its value partially represents the even less significant bits that have been truncated in the calculations. These three bits are only used while doing calculations and aren't stored in the floating-point variable before or after the calculations.
This is what you should do in order to round the result to the nearest even number using G
, R
and S
:
GRS - Action
0xx - round down = do nothing (x means any bit value, 0 or 1)
100 - this is a tie: round up if the mantissa's bit just before G is 1, else round down=do nothing
101 - round up
110 - round up
111 - round up
Rounding up is done by adding 1 to the mantissa in the mantissa's least significant bit position just before G
. If the mantissa overflows (its 23 least significant bits that you will store become zeroes), you have to add 1 to the exponent. If the exponent overflows, you set the number to +infinity or -infinity depending on the number's sign.
In the case of a tie, you add 1 to the mantissa if the mantissa is odd and you add nothing if it's even. That's what makes the result rounded to the nearest even value.
这篇关于如何即使浮点数轮来执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!