About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
64-bit unsigned integer array.
npm install @stdlib/array-uint64Alternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use the ES Module available on theesmbranch (see README). - If you are using Deno, visit the
denobranch (see README for usage intructions). - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umdbranch (see README).
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
var Uint64Array = require( '@stdlib/array-uint64' );Creates a 64-bit unsigned integer array.
var arr = new Uint64Array();
// returns <Uint64Array>Creates a 64-bit unsigned integer array having a specified length.
var arr = new Uint64Array( 5 );
// returns <Uint64Array>[ 0n, 0n, 0n, 0n, 0n ]Creates a 64-bit unsigned integer array from another typed array.
var Uint32Array = require( '@stdlib/array-uint32' );
var arr1 = new Uint32Array( [ 5, 5, 5 ] );
var arr2 = new Uint64Array( arr1 );
// returns <Uint64Array>[ 5n, 5n, 5n ]Creates a 64-bit unsigned integer array from an array-like object or iterable.
var arr = new Uint64Array( [ 5.0, 5.0, 5.0 ] );
// returns <Uint64Array>[ 5n, 5n, 5n ]Returns a 64-bit unsigned integer array view of an ArrayBuffer.
var ArrayBuffer = require( '@stdlib/array-buffer' );
var buf = new ArrayBuffer( 32 );
var arr = new Uint64Array( buf, 0, 4 );
// returns <Uint64Array>[ 0n, 0n, 0n, 0n ]Static property returning the size (in bytes) of each array element.
var nbytes = Uint64Array.BYTES_PER_ELEMENT;
// returns 8Static property returning the constructor name.
var str = Uint64Array.name;
// returns 'Uint64Array'Read-only property which returns the underlying ArrayBuffer referenced by array instance.
var arr = new Uint64Array( 5 );
var buf = arr.buffer;
// returns <ArrayBuffer>Read-only property which returns the length (in bytes) of the array instance.
var arr = new Uint64Array( 5 );
var byteLength = arr.byteLength;
// returns 40Read-only property which returns the offset (in bytes) of the array instance from the start of its underlying ArrayBuffer.
var arr = new Uint64Array( 5 );
var byteOffset = arr.byteOffset;
// returns 0Size (in bytes) of each array element.
var arr = new Uint64Array( 5 );
var nbytes = arr.BYTES_PER_ELEMENT;
// returns 8Read-only property which returns the number of array elements.
var arr = new Uint64Array( 5 );
var len = arr.length;
// returns 5Creates a new 64-bit unsigned integer array from an array-like object or an iterable.
var arr = Uint64Array.from( [ 1, 2 ] );
// returns <Uint64Array>[ 1n, 2n ]To invoke a function for each src value, provide a callback function.
function mapFcn( v ) {
return v * 2;
}
var arr = Uint64Array.from( [ 1, 2 ], mapFcn );
// returns <Uint64Array>[ 2n, 4n ]A callback function is provided two arguments:
- value: source value.
- index: source index.
To set the callback execution context, provide a thisArg.
function mapFcn( v ) {
this.count += 1;
return v * 2;
}
var ctx = {
'count': 0
};
var arr = Uint64Array.from( [ 1, 2 ], mapFcn, ctx );
// returns <Uint64Array>[ 2n, 4n ]
var n = ctx.count;
// returns 2Creates a new 64-bit unsigned integer array from a variable number of arguments.
var arr = Uint64Array.of( 1, 2 );
// returns <Uint64Array>[ 1n, 2n ]Returns an array element located at position (index) i.
var arr = new Uint64Array( 10 );
// Set the first element:
arr.set( 1, 0 );
// Get the first element:
var z = arr.get( 0 );
// returns <Uint64>[ 1n ]If provided an out-of-bounds index, the method returns undefined.
var arr = new Uint64Array( 10 );
var z = arr.get( 100 );
// returns undefinedSets one or more array elements.
var Uint64 = require( '@stdlib/number-uint64-ctor' );
var arr = new Uint64Array( [ 1, 2, 3 ] );
// returns <Uint64Array>[ 1n, 2n, 3n ]
// Get the first element:
var z = arr.get( 0 );
// returns <Uint64>[ 1n ]
// Set the first element:
arr.set( new Uint64( 5 ) );
// Get the first element:
z = arr.get( 0 );
// returns <Uint64>[ 5n ]By default, the method sets array elements starting at position (index) i = 0. To set elements starting elsewhere in the array, provide an index argument i.
var Uint64 = require( '@stdlib/number-uint64-ctor' );
var arr = new Uint64Array( [ 1, 2, 3 ] );
// returns <Uint64Array>[ 1n, 2n, 3n ]
// Get the third element:
var z = arr.get( 2 );
// returns <Uint64>[ 3n ]
// Set the third element:
arr.set( new Uint64( 5 ), 2 );
// Get the third element:
z = arr.get( 2 );
// returns <Uint64>[ 5n ]In addition to providing a scalar value (e.g., nonnegative integer, bigint, or Uint64), to set one or more array elements, provide an array-like object containing scalar values
var Uint64 = require( '@stdlib/number-uint64-ctor' );
var arr = new Uint64Array( [ 1, 2, 3 ] );
// returns <Uint64Array>[ 1n, 2n, 3n ]
// Set the first two array elements:
arr.set( [ 4, 5 ] );
var z = arr.get( 0 );
// returns <Uint64>[ 4n ]
z = arr.get( 1 );
// returns <Uint64>[ 5n ]A few notes:
- If
iis out-of-bounds, the method throws an error. - If a target array cannot accommodate all values (i.e., the length of source array plus
iexceeds the target array length), the method throws an error. - If provided a typed array which shares an
ArrayBufferwith the target array, the method will intelligently copy the source range to the destination range.
-
While a
Uint64Arraystrives to maintain (but does not guarantee) consistency with typed arrays, significant deviations from ECMAScript-defined typed array behavior are as follows:- The constructor does not require the
newoperator. - The constructor and associated methods support a broader variety of input argument types in order to better accommodate unsigned integer input.
- Accessing array elements using bracket syntax (e.g.,
X[i]) is not supported. Instead, one must use the.get()method. - The
setmethod has extended behavior in order to support 64-bit unsigned integer instances.
- The constructor does not require the
var Uint64 = require( '@stdlib/number-uint64-ctor' );
var logEach = require( '@stdlib/console-log-each' );
var Uint32Array = require( '@stdlib/array-uint32' );
var Uint64Array = require( '@stdlib/array-uint64' );
// Create a 64-bit unsigned integer array by specifying a length:
var out = new Uint64Array( 3 );
logEach( '%s', out );
// Create a 64-bit unsigned integer array from an array of 64-bit unsigned integer numbers:
var arr = [
new Uint64( 1 ),
new Uint64( 2 ),
new Uint64( 3 )
];
out = new Uint64Array( arr );
logEach( '%s', out );
// Create a 64-bit unsigned integer array from a typed array:
arr = new Uint32Array( [ 1, 2, 3, 4 ] );
out = new Uint64Array( arr );
logEach( '%s', out );
// Create a 64-bit unsigned integer array from an array buffer, where underlying storage consists of interleaved high and low 32-bit words:
arr = new Uint32Array( [ 1, 2, 3, 4 ] );
out = new Uint64Array( arr.buffer );
logEach( '%s', out );
// Create a 64-bit unsigned integer array from an array buffer view, where underlying storage represents each 64-bit integer as interleaved high and low 32-bit words:
arr = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
out = new Uint64Array( arr.buffer, 16, 2 );
logEach( '%s', out );This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2026. The Stdlib Authors.