问题
Am I correct to conclude that:
all integers with exponent over 52 in the 64 bit floating point will be even? For example, if exponent is
53
, and the mantissa is0000000000000000000000000000000000000000000000000001
, then the number is100000000000000000000000000000000000000000000000000010
- ends in10
. If the mantissa is54
the number ends with100
.the more we increase the exponent, the more integer numbers can not be represented - for the exponent of
54
- it's impossible to represent one number -9007199254740993
, with exponent of55
- we can't represent3
numbers (because we have two bits left out of mantissa which can have combinations of 01,10,11).
回答1:
all integers with exponent over 52 in the 64 bit floating point will be even?
Yes. F64 has 52 encoded mantissa bits, plus an implied one. We are talking about an 'unbiased' exponent, so your value is 2^exp*1.mant
.
Imagine that to convert the F64 to an integer, the mantissa will be left-shifted by the unbiased exponent. Shifting by 52 will guarantee an integer that doesn't need rounding. 53 will guarantee an even number as zeroes are shifted in like you showed.
the more we increase the exponent, the more integer numbers can not be represented
Yes, but this goes much faster than you describe. Your example value is simply this first occurrence. In the range (2^53, 2^54) where only even numbers can be represented like you stated, only half of all integers exist in the F64, so in that range all 2^52 odd integers are unrepresented.
来源:https://stackoverflow.com/questions/39304010/are-all-integers-with-exponent-over-52-are-even-in-64-bit-floating-point