IEEE-754:有理数集的基数 [英] IEEE-754: cardinality of the set of rational numbers

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

问题描述

有理数集的基数是什么?这些有理数具有与单精度IEEE-754兼容的浮点格式的精确表示?

What is the cardinality of the set of rational numbers, which have an exact representation in floating point format compatible with single-precision IEEE-754?

推荐答案

有2139095039个有限的正浮点数. 有限的负浮点数很多.

There are 2139095039 finite positive floats. There are as many finite negative floats.

您想将+0.0和-0.0包括为两项还是一项?根据答案的不同,总数为2 * 2139095039 + 2或2 * 2139095039 +1,分别为4278190080或4278190079.

Do you want to include +0.0 and -0.0 as two items or as one? Depending on the answer the total is 2 * 2139095039 + 2 or 2 * 2139095039 + 1, that is, respectively, 4278190080 or 4278190079.

2139095039编号的来源:

Source for the 2139095039 number:

#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  float f = FLT_MAX;
  unsigned int i;
  memcpy(&i, &f, 4);
  printf("%u\n", i);
}

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

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