node-int64
node-int64 copied to clipboard
The value is wrong when pass a number to constructor
When I pass a number to constructor, I got the wrong value:
// the following output is both [Int64 value:Infinity octets:10 00 00 00 00 00 00 00]
new Int64(Number('1152921504606846977'));
new Int64(0x1000000000000001);
I believe that is caused by the mod operation of big integer:
const VAL32 = 0x10000000;
0x1000000000000001 % VAL32 // 0
0x100000000000001a % VAL32 // 0
0x1000000000000100 % VAL32 // 256, ok
This is behaving as expected. Number('1152921504606846977') and 0x1000000000000001 both exceed Number.MAX_SAFE_INTEGER. To instantiate Int64's with values > MAX_SAFE_INTEGER, you need to pass the 4 high and 4 low bytes as two 32-bit values. E.g.
> new Int64(0x10000000, 0x00000001)
[Int64 value:Infinity octets:10 00 00 00 00 00 00 01]