64-bit Integer vs. 64-bit Float: which one has more values?

Question:

Which has more values, a 64-bit integer or a 64-bit float?

My answer is that float has more value because its more accurate.

But isn’t integer is always greater than a float ?

Asked By: Quark

||

Answers:

There are more unique values in a 64-bit integer (2^64 for a two’s complement machine).

However, a 64-bit float has much larger range of values.

This can be trivially reasoned about because a 64-bit integer has a unique bit pattern for each unique value (it is "100% efficient") while a 64-bit float has a dedicated sign bit (which allows for a -0, but -0 == 0 is true) as well as a few "special patterns" (e.g. NaN, which has multiple representations) thereby reducing the total number of unique values the float can represent.

See the IEEE-754 article on Wikipedia and see the sections on the Representation of non-numbers

Answered By: user166390
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.