IEEE 754 实数可以“覆盖"吗?其范围内的所有整数? [英] Can a IEEE 754 real number "cover" all integers within its range?

查看:18
本文介绍了IEEE 754 实数可以“覆盖"吗?其范围内的所有整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对原始问题进行了编辑(缩短)以关注精度问题,而不是范围问题.

单精度或双精度,实数的每种表示都限于 (-range,+range).在这个范围内有一些整数(1、2、3、4……等等;负数也是如此).

Single, or double precision, every representation of real number is limited to (-range,+range). Within this range lie some integer numbers (1, 2, 3, 4..., and so on; the same goes with negative numbers).

是否保证 IEEE 754 实数(浮点数、双精度数等)可以覆盖"其范围内的所有整数?覆盖"是指实数将准确表示整数,而不是(例如)5.000001".

Is there a guarantee that a IEEE 754 real number (float, double, etc) can "cover" all integers within its range? By "cover" I mean the real number will represent the integer number exactly, not as (for example) "5.000001".

提醒一下:http://www3.ntu.edu.sg/home/ehchua/programming/java/DataRepresentation.html 对各种数字表示格式的很好解释.

Just as reminder: http://www3.ntu.edu.sg/home/ehchua/programming/java/DataRepresentation.html nice explanation of various number representation formats.

更新:

因为问题是关于可以"的,我也在寻找无法做到的事实——因为它引用一个数字就足够了.例如不,它不能做,例如数字 1748574 不能完全用浮点数表示"(这个数字当然是凭空而来的).

Because the question is for "can" I am also looking for the fact this cannot be done -- for it quoting a number is enough. For example "no it cannot be done, for example number 1748574 is not represented exactly by float number" (this number is taken out of thin air of course).

对于好奇的读者

如果你想玩 IEEE 754 表示——在线计算器:http:///www.ajdesigner.com/fl_ieee_754_word/ieee_32_bit_word.php

If you would like to play with IEEE 754 representation -- on-line calculator: http://www.ajdesigner.com/fl_ieee_754_word/ieee_32_bit_word.php

推荐答案

macias,为了补充 phant0m 已经很好的答案(赞成;我建议你接受它),我会用你自己的话.

macias, to add to the already excellent answer by phant0m (upvoted; I suggest you accept it), I'll use your own words.

不,这是不可能的,例如数字 16777217 不能完全由浮点数表示."

"No it cannot be done, for example number 16777217 is not represented exactly by float number."

此外,例如数字 9223372036854775809 不能完全由双数表示".

Also, "for example number 9223372036854775809 is not represented exactly by double number".

这是假设您的计算机使用的是 IEEE 浮点格式,这是一个非常好的选择.

This is assuming your computer is using the IEEE floating point format, which is a pretty strong bet.

这篇关于IEEE 754 实数可以“覆盖"吗?其范围内的所有整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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