如何即使浮点数轮来执行 [英] How to perform round to even with floating point numbers

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

问题描述

在关于IEEE-754单precision浮点,你怎么执行就近舍,那里的联系轮所需的位置最近,即使数字(默认是迄今为止最常用的模式)<? / p>

基本上我有看守位,轮位和粘滞位。
因此,如果我们形成这些入载体,并称之为遗传资源,则遵循以下规则:


  1. 如果 G = 0 ,本轮下跌(什么都不做)

  2. 如果 G = 1 RS == 10 RS == 01 ,圆(加一个尾数)

  3. 如果 GSR = 111 ,轮甚至

所以,我不知道如何进行舍入到最近。任何帮助是极大的AP preciated。


解决方案

只是为了确保我们在同一页上,是最显著位三,研究随之而来的和取值可以被认为是最不显著位,因为它的价值部分重新presents已在计算被截断的甚至更少显著比特。这三个位仅用于同时操作的方式计算和之前或计算之后不存储在浮点变量

这是你应该为了圆结果使用最接近的偶数做什么研究取值

GRS - 行动结果
0XX - 本轮下跌=什么也不做(X指任何位值0或1)结果
100 - 这是一个领带:圆了,如果尾数的位之前的为1,否则本轮下跌=无能为力结果
101 - 围捕结果
110 - 围捕结果
111 - 围捕

四舍五入是通过添加1在尾数上最显著比特位尾数刚之前完成。如果尾数溢出(其23,你将成为存储至少零位显著),您必须加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:

  1. If G = 0, round down (do nothing)
  2. If G = 1, and RS == 10 or RS == 01, round up (add one to mantissa)
  3. 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屋!

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