const count = 1000;
const nums = crypto.getRandomValues(new Uint32Array(count));
const bools = Array.from(nums, (_) => Math.random() < 0.5);
const result = [];
const view = new DataView(new ArrayBuffer(8));
function test1_wrong(low, high, isUnsigned) {
const unsigned = (BigInt(high >>> 0) << BigInt(32)) | BigInt(low >>> 0);
return unsigned;
}
function test1(low, high, isUnsigned) {
const unsigned = (BigInt(high >>> 0) << BigInt(32)) | BigInt(low >>> 0);
if (!isUnsigned && (unsigned & BigInt(1) << BigInt(63))) {
return unsigned - (BigInt(1) << BigInt(64));
}
return unsigned;
}
function test1_literals(low, high, isUnsigned) {
const unsigned = (BigInt(high >>> 0) << 32n) | BigInt(low >>> 0);
if (!isUnsigned && (unsigned & (1n << 63n))) {
return unsigned - (1n << 64n);
}
return unsigned;
}
function test2(low, high, isUnsigned) {
view.setUint32(0, low, true);
view.setUint32(4, high, true);
return isUnsigned ? view.getBigUint64(0, true) : view.getBigInt64(0, true);
}