Skip to content
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!

Uint64Array

NPM version Build Status Coverage Status

64-bit unsigned integer array.

Installation

npm install @stdlib/array-uint64

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (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.

Usage

var Uint64Array = require( '@stdlib/array-uint64' );

Uint64Array()

Creates a 64-bit unsigned integer array.

var arr = new Uint64Array();
// returns <Uint64Array>

Uint64Array( length )

Creates a 64-bit unsigned integer array having a specified length.

var arr = new Uint64Array( 5 );
// returns <Uint64Array>[ 0n, 0n, 0n, 0n, 0n ]

Uint64Array( typedarray )

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 ]

Uint64Array( obj )

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 ]

Uint64Array( buffer[, byteOffset[, length]] )

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 ]

Properties

Uint64Array.BYTES_PER_ELEMENT

Static property returning the size (in bytes) of each array element.

var nbytes = Uint64Array.BYTES_PER_ELEMENT;
// returns 8

Uint64Array.name

Static property returning the constructor name.

var str = Uint64Array.name;
// returns 'Uint64Array'

Uint64Array.prototype.buffer

Read-only property which returns the underlying ArrayBuffer referenced by array instance.

var arr = new Uint64Array( 5 );

var buf = arr.buffer;
// returns <ArrayBuffer>

Uint64Array.prototype.byteLength

Read-only property which returns the length (in bytes) of the array instance.

var arr = new Uint64Array( 5 );

var byteLength = arr.byteLength;
// returns 40

Uint64Array.prototype.byteOffset

Read-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 0

Uint64Array.prototype.BYTES_PER_ELEMENT

Size (in bytes) of each array element.

var arr = new Uint64Array( 5 );

var nbytes = arr.BYTES_PER_ELEMENT;
// returns 8

Uint64Array.prototype.length

Read-only property which returns the number of array elements.

var arr = new Uint64Array( 5 );

var len = arr.length;
// returns 5

Methods

Uint64Array.from( src[, map[, thisArg]] )

Creates 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 2

Uint64Array.of( element0[, element1[, ...elementN]] )

Creates a new 64-bit unsigned integer array from a variable number of arguments.

var arr = Uint64Array.of( 1, 2 );
// returns <Uint64Array>[ 1n, 2n ]

Uint64Array.prototype.get( i )

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 undefined

Uint64Array.prototype.set( value[, i] )

Sets 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 i is out-of-bounds, the method throws an error.
  • If a target array cannot accommodate all values (i.e., the length of source array plus i exceeds the target array length), the method throws an error.
  • If provided a typed array which shares an ArrayBuffer with the target array, the method will intelligently copy the source range to the destination range.


Notes

  • While a Uint64Array strives 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 new operator.
    • 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 set method has extended behavior in order to support 64-bit unsigned integer instances.

Examples

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 );

Notice

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.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.