我怎么这一轮二进制数最接近的偶数 [英] How do I round this binary number to the nearest even

查看:185
本文介绍了我怎么这一轮二进制数最接近的偶数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种二元再presentation 0.1

  0.00011001100110011001100110011001100110011001100110011001100110

我需要将其舍入到最接近甚至可以将其存储在双precision浮点。我似乎无法了解如何做到这一点。大多数教程谈论后卫,圆粘位 - 哪儿?他们在这再presentation

此外,我已经找到了如下解释:


  

让我们看看0.1看起来像双precision。首先,让我们写
  以二进制,截断到57位显著:


  0.000110011001100110011001100110011001100110011001100110011001 ...


  

54位及以后总要有点超过一半的价值
  位置53,所以这轮高达


  0.0001100110011001100110011001100110011001100110011001101

这个人不谈论GRS位,为什么?难道他们不总是需要?


解决方案

您引用的文字是从我的文章的 0.1为什么中不存在浮点。在这篇文章中,我展示了如何用手工做转换,而GRS位是IEEE实现细节。即使你使用的是电脑做的转换,你不必使用IEEE运算(的,你不应该,如果你想这样做正确的),所以GRS位将无法发挥作用有两种。在任何情况下,GRS位适用于计算,而不是真的要转换的概念想法。

I have this binary representation of 0.1:

0.00011001100110011001100110011001100110011001100110011001100110

I need to round it to the nearest even to be able to store it in the double precision floating point. I can't seem to understand how to do that. Most tutorials talk about guard, round and sticky bits - where are they in this representation?

Also I've found the following explanation:

Let’s see what 0.1 looks like in double-precision. First, let’s write it in binary, truncated to 57 significant bits:

0.000110011001100110011001100110011001100110011001100110011001…

Bits 54 and beyond total to greater than half the value of bit position 53, so this rounds up to

0.0001100110011001100110011001100110011001100110011001101

This one doesn't talk about GRS bits, why? Aren't they always required?

解决方案

The text you quote is from my article Why 0.1 Does Not Exist In Floating-Point . In that article I am showing how to do the conversion by hand, and the "GRS" bits are an IEEE implementation detail. Even if you are using a computer to do the conversion, you don't have to use IEEE arithmetic (and you shouldn't if you want to do it correctly ), so the GRS bits won't come into play there either. In any case, the GRS bits apply to calculations, not really to the conceptual idea of conversion.

这篇关于我怎么这一轮二进制数最接近的偶数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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