十进制数和精确表示 [英] decimal number and exact representation

查看:148
本文介绍了十进制数和精确表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++中,如何知道十进制数字何时可以使用IEEE 754-1985标准来精确表示。
例如0.2不能正确表示。

In c++, how to know when a decimal number can be exactly representing using IEEE 754-1985 standard. for instance 0.2 cannot be representing exactly.

有没有简单的规则?

推荐答案

如果一个数字可以写成 B  ×  2 n ,其中 B 是一个整数(而且 B n 属于某个有效范围)。换句话说,必须有一些整数 n ,这样如果你把你的号码转换为2,那么你得到一个整数。显然,对于1/5,没有这样的 n

A number can be represented exactly as an IEEE755 float if it can be written as B × 2n, where B is an integer (and B and n fall into some valid range). In other words, there must be some integer n such that if you mutliply your number by 2n you get an integer. Clearly for 1/5 there is no such n.

另一种说法是你的号码必须是有限的总和许多两个不相干的权力(权力之间的最大距离是浮动的精度)。

Yet another way of saying it is that your number has to be the sum of finitely many powers of two which are not too far apart (the maximal distance between the powers is the precision of your float).

另一种说得很松散的方法是分母是二分之一的有理数表示(尽管有明显的精确约束)。

Yet another way to say it very loosely is that "rational numbers whose denominator is a power of two" are representably (though with the obvious precision constraints).

浮点的精度,即 B 是24位,单位为53位,双精度为53位,双精度为64位。

The precision of the float, which is the width of B, is 24 bits for single, 53 bits for double and 64 bits for extended double precision.

这篇关于十进制数和精确表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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