Is a MongoDB's NumberLong really 64 bit signed integer really 64 bit?
MongoDB's NumberLong is said to be a 64 bit signed integer, which should mean we can play with -2^63 <= x <= 2^63-1, where x is a NumberLong.
However, adding 1 or subtracting 1 from a NumberLong(x) does not return the expected value for x <= -2^54 or x >= 2^54, but correct values are returned for -2^53 <= x <= 2^53.
The reliable NumberLong numbers therefor seem to be 54 bit signed integers.
Why is this?
Am I doing someting wrong?
Sample from the mongo shell:
> NumberLong( Math.pow(2,54) )
NumberLong("18014398509481984") // Expected
> NumberLong( Math.pow(2,54)-1 )
NumberLong("18014398509481984") // **NOT** Expected
> NumberLong( -Math.pow(2,54) )
NumberLong("-18014398509481984") // Expected
> NumberLong( -Math.pow(2,54)+1 )
NumberLong("-18014398509481984") // **NOT** Expected
> NumberLong( Math.pow(2,53) )
NumberLong("9007199254740992") // Expected
> NumberLong( Math.pow(2,53)-1 )
NumberLong("9007199254740991") // Expected
> NumberLong( -Math.pow(2,53) )
NumberLong("-9007199254740992") // Expected
> NumberLong( -Math.pow(2,53)+1 )
NumberLong("-9007199254740991") // Expected
Using MongoDB 2.0.0