0

Given a range of representable floating point numbers, how can I go about calculating the number of bits of precision that I will be able to store in a IEE 754 32-bit float in that range.

For instance, when performing a mathematical calculation where the result and numbers in question are expected to end up in a range of -1 to 1 or say 0 to 16, how would I go about calculating how many theoretical bits of precision exist within said range?

I realize that the values don't have even spacing and are more concentrated around 0, so this complicates the question. In the end, I want to understand what values will not be rounded and how many significant digits I can expect within a range. For instance, can I expect to store (without rounding), a value with accuracy down to 0.000001 in the range of -1 to 1? How would I go about calculating this?

4

1 回答 1

1

你不必做太多的工作来找出你的答案。一个 32 位 IEEE 754 浮点数有 23 位尾数;计算前导 1 给出 24 个有效二进制数字(注意 denorms)。通过做一些对数或在 wikipedia 上的表格中查找它,您会看到大约 7.22 个十进制数字。

让我们把这个事实应用到你的一个例子中。因此,您想要的所有数字(精度低至 0.000001 的数字)都可以在 -1 到 1 的范围内表示 - 这些数字都有 7 个或更少的有效数字。

至于您关于计算某个范围内的理论精度位的其他问题 - 到处都是一样的。精度与幅度无关 - 您在任何地方都获得相同数量的有效数字(再次注意 denorms)。正如您所提到的,在绝对意义上,可表示的数字确实开始更加间隔开。

如果您想要不四舍五入的数字,您需要选择可以完全表示为二进制分数乘以 2 的幂的数字。

于 2013-06-15T15:53:20.970 回答