I know about weird stuff with precision errors, but I can’t fathom,
Why is (long)9223372036854665200d giving me 9223372036854665216 ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
9223372036854665200dis a constant of typedouble. However,9223372036854665200does not fit in adoublewithout loss of precision. Adoubleonly has 52 bits of mantissa, whereas the number in question requires 63 bits to be represented exactly.The nearest
doubleto9223372036854665200dis the number whose mantissa equals1.1111111111111111111111111111111111111111111110010100in binary and whose exponent is 63 (decimal). This number is none other than9223372036854665216(call itU).If we decrease the mantissa one notch to
1.1...0011, we get9223372036854664192(call itL).The original number is between
LandUand is much closer toUthan it is toLFinally, if you think that this truncation of the mantissa ought to result in a number that ends in a bunch of zeros, you’re right. Only it happens in binary, not in decimal:
Uin base-16 is0x7ffffffffffe5000andLis0x7ffffffffffe4c00.