mirror of
https://github.com/LukeHagar/relay.git
synced 2025-12-06 04:21:14 +00:00
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
"use strict";
|
|
// Integer Utility
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getUint64 = exports.getInt64 = exports.setInt64 = exports.setUint64 = exports.UINT32_MAX = void 0;
|
|
exports.UINT32_MAX = 4294967295;
|
|
// DataView extension to handle int64 / uint64,
|
|
// where the actual range is 53-bits integer (a.k.a. safe integer)
|
|
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);
|
|
}
|
|
exports.setUint64 = setUint64;
|
|
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);
|
|
}
|
|
exports.setInt64 = setInt64;
|
|
function getInt64(view, offset) {
|
|
const high = view.getInt32(offset);
|
|
const low = view.getUint32(offset + 4);
|
|
return high * 4294967296 + low;
|
|
}
|
|
exports.getInt64 = getInt64;
|
|
function getUint64(view, offset) {
|
|
const high = view.getUint32(offset);
|
|
const low = view.getUint32(offset + 4);
|
|
return high * 4294967296 + low;
|
|
}
|
|
exports.getUint64 = getUint64;
|
|
//# sourceMappingURL=int.js.map
|