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 ?
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
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 ?
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