CKTIS / JavaScript
BigUint64Array: unsigned 64-bit integers
BigUint64Array stores BigInt values as unsigned 64-bit integers and wraps them modulo 2^64.
Version: ECMAScript 2020 onward; example target: Node.js 24.22.2
Syntax
new BigUint64Array(); new BigUint64Array(length); new BigUint64Array(source); new BigUint64Array(buffer[, byteOffset[, length]])new BigUint64Array(source?, byteOffset?, length?) creates an unsigned typed array with 8 bytes per element. The source can be a length, an iterable or array-like value, BigInt64Array/BigUint64Array, or a buffer; a numeric typed array has a different content type and throws TypeError. The buffer form is a view without copying, and byteOffset must be a multiple of 8.
Assignment converts a value to BigInt and reduces it modulo 2^64, so -1n becomes 2^64 - 1 and 2^64 + 5 becomes 5n. An ordinary Number throws TypeError; BigInt(number) accepts only an integral Number, while a fractional one throws RangeError. Byte order is platform-native; use DataView for a fixed binary format.
Length goes through ToIndex: fractions truncate toward zero, NaN/undefined become 0, and -0.5 also gives 0. A negative result after ToIntegerOrInfinity, infinity, excessive range, a misaligned offset, or a range beyond the buffer throws RangeError. A detached buffer and incompatible values throw TypeError. The API dates to ECMAScript 2020; BYTES_PER_ELEMENT is 8.
Examples
const values = new BigUint64Array([0n, -1n, 2n ** 64n + 5n]);
console.log(Array.from(values, String).join(","));
const buffer = new ArrayBuffer(16);
const view = new BigUint64Array(buffer, 8, 1);
view[0] = 42n;
console.log(view.byteOffset, view.byteLength, view[0], BigUint64Array.BYTES_PER_ELEMENT);
console.log(new BigUint64Array(2.9).length, new BigUint64Array(-0.5).length);
try { values[0] = 1; } catch (error) { console.log(error instanceof TypeError); }
try { new BigUint64Array(new Uint8Array([1])); } catch (error) { console.log(error instanceof TypeError); }Result
0,18446744073709551615,5 8 8 42n 8 2 0 true true