27 lines
985 B
JavaScript
27 lines
985 B
JavaScript
// Integer Utility
|
|
export const UINT32_MAX = 4294967295;
|
|
// DataView extension to handle int64 / uint64,
|
|
// where the actual range is 53-bits integer (a.k.a. safe integer)
|
|
export function setUint64(view, offset, value) {
|
|
const high = value / 4294967296;
|
|
const low = value; // high bits are truncated by DataView
|
|
view.setUint32(offset, high);
|
|
view.setUint32(offset + 4, low);
|
|
}
|
|
export function setInt64(view, offset, value) {
|
|
const high = Math.floor(value / 4294967296);
|
|
const low = value; // high bits are truncated by DataView
|
|
view.setUint32(offset, high);
|
|
view.setUint32(offset + 4, low);
|
|
}
|
|
export function getInt64(view, offset) {
|
|
const high = view.getInt32(offset);
|
|
const low = view.getUint32(offset + 4);
|
|
return high * 4294967296 + low;
|
|
}
|
|
export function getUint64(view, offset) {
|
|
const high = view.getUint32(offset);
|
|
const low = view.getUint32(offset + 4);
|
|
return high * 4294967296 + low;
|
|
}
|
|
//# sourceMappingURL=int.mjs.map
|