|
The sign reversal is interesting and may be our bug. But I think that the loss of precision is because JavaScript's native numeric format is floating point.
> NumberLong(9223372036854775807) // unquoted number is interpreted as negative
|
NumberLong("-9223372036854775808")
|
> NumberLong("9223372036854775807") // quoted number echoes as itself
|
NumberLong("9223372036854775807")
|
> NumberLong(9223372036854775807) + 0 // JavaScript has rounded the number
|
-9223372036854776000
|
> NumberLong("9223372036854775807") + 0 // quoted version is rounded, but no sign reversal
|
9223372036854776000
|
The number that JavaScript rounds off to overflows 63 bits (i.e. into the sign bit), which may be where the sign reversal is coming from.
9223372036854775807 is 0x7FFFFFFF'FFFFFFFF.
9223372036854776000 is 0x80000000'000000C0 (if I calculated it right).
|