64-bit Integer and 64-bit Float: Who Has More Values?

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

My answer is that float matters more because it is more accurate.

But isn't an integer always greater than a float?


source to share

1 answer

In 64-bit, an integer (2 ^ 64 for a two-piece machine) has more unique values.

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

This can be trivially argued because a 64-bit integer has a unique bit pattern for each unique value (it's "100% efficient"), while a 64-bit float has a dedicated sign bit (which allows - 0, but - 0 == 0 is true ), as well as a few "special patterns" (like one NaN

that has multiple representations ), thereby reducing the total number of unique values ​​that a float can represent.

See the IEEE-754 article on Wikipedia and see the Non-Number Representation sections