-
Notifications
You must be signed in to change notification settings - Fork 79
64 bit integers
Note
This page has been updated for jDataView 3
Because jDataView extends JavaScript's built-in DataView
class, the setBigInt64
, setBigUint64
, getBigInt64
, and getBigUint64
methods work as you would expect.
Of course, jDataView also has corresponding writeXXX
versions: writeBigInt64
, and writeBigUint64
.
Warning
For values larger than Number.MAX_SAFE_INTEGER
, consider using the BigInt
methods above.
jDataView was around before BigInt
s existed! At the time, there was no option but to implement Int64 methods in a bespoke way.
Now, these methods are kept as helpful utilities. Be careful though, because they'll just return regular numbers, so you will lose precision when reading very large numbers.
See writeXXX methods to understand the write
variants of the set
methods.
(with jDataView extensions for sequential writes)
getBigInt64(byteOffset: number | undefined, littleEndian?: boolean): bigint
setBigInt64(byteOffset: number | undefined, value: bigint, littleEndian?: boolean): void
writeBigInt64(value: bigint, littleEndian?: boolean): void
getBigUint64(byteOffset: number | undefined, littleEndian?: boolean): bigint
setBigUint64(byteOffset: number | undefined, value: bigint, littleEndian?: boolean): void
writeBigUint64(value: bigint, littleEndian?: boolean): void
// Get a 64 bit integer. Returns a regular Number, not a BigInt.
// For more precision, use `getBigInt64()`
getInt64(byteOffset: number | undefined, littleEndian?: boolean): number
// Sets a 64 bit integer. Takes a regular Number, not a BigInt.
// For more precision, use `setBigInt64()`
setInt64(byteOffset: number | undefined, value: number, littleEndian?: boolean): void
writeInt64(value: number, littleEndian?: boolean): void
// Get an unsigned 64 bit integer. Returns a regular Number, not a BigInt.
// For more precision, use `getBigUint64()`
getUint64(byteOffset: number | undefined, littleEndian?: boolean): number
// Sets an unsigned 64 bit integer. Takes a regular Number, not a BigInt.
// For more precision, use `setBigUint64()`
setUint64(byteOffset: number | undefined, value: number, littleEndian?: boolean): void
writeUint64(value: number, littleEndian?: boolean): void