IEEE 754中有多少个整数 [英] how many whole numbers in IEEE 754

查看:261
本文介绍了IEEE 754中有多少个整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出在ieee 754中存在多少个不同的整数。我得到的数字是1778384895,但我找不到任何资源来检查我自己。
非常感谢。

解决方案

我会假设单精度浮点数。

我们得到了零,虽然可以表示为负零,但仍然只是零作​​为一个整数,所以我把它算为一个。



指数小于127的数字不是整数。

 指数空位#数字
127 0 1
128 1 2
129 2 4
...
149 22 2 ^ 22

这些总和为 2 ^ 23-1 。如果指数大于149,所有的数字都是整数。所以这是一个额外的 105 * 2 ^ 23 数字(指数255是保留的)。所有这些都是正面的和负面的。

总计是

pre $ 1 +((2 ^ 23-1)+ 105 *(2 ^ 23))* 2 = 1778384895

所以看起来你是对的。很好的问题,乍看起来很容易:)

I am trying to figure out how many different whole numbers exist in the ieee 754. The number I got was 1778384895 but I couldn't find any resource to check myself. Thanks a lot in advance.

解决方案

I will assume single precision floats.

We got the zero, which although can be represented as negative zero, is still just zero as an integer so I count it as one.

Numbers with exponent less than 127 are not integers.

Exponent   Free bits   # Numbers
127        0           1
128        1           2
129        2           4
...
149        22          2^22

These sum up to 2^23-1. If exponent is greater than 149, all the numbers are integers. So that's an additional 105*2^23 numbers (exponent 255 is reserved). All of these come in positive and negative.

The grand total is thus

1 + ((2^23 - 1) + 105 * (2^23)) * 2 = 1778384895

So looks like you were right. Nice question, it looked a lot easier at first sight :)

这篇关于IEEE 754中有多少个整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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