mathfloating-pointieee-754

Can a IEEE 754 real number "cover" all integers within its range?


The original question was edited (shortened) to focus on a problem of precision, not range.

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).

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".

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

Update:

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).

For curious reader

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


Solution

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

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

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

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