-
Notifications
You must be signed in to change notification settings - Fork 15
Description
The forceReadVint() function doesn't make sense.
You have (result << 32) | getUint32() which doesn't make sense in javascript, since binary operations work on 31-bit signed integers.
This is because js uses 32-bit integers where 1 bit is reserved.
Also in javascript doing my_int << 32 actually returns my_int, as if you didn't do anything.
This is sometimes used to convert float to int, where doing 5.67 << 32 would return 5.
Note that (result << 16) | getUint16() also wont work, because it would require a 32-bit unsigned integer (16 bits for current result value and another 16 bits that you are adding), which you don't have.
I'm guessing you copied this code from a language that had support for 64-bit integers.
You can make it work by replacing << with multiplication and | with addition, which would treat the number as a double float.
This wont give you a full 64-bit int, but that shouldn't matter. Alternative would be to use BigInt.