diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/README.md b/lib/node_modules/@stdlib/number/uint64/ctor/README.md new file mode 100644 index 000000000000..5c8f9d62403b --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/README.md @@ -0,0 +1,262 @@ + + +# Uint64 + +> Unsigned 64-bit integer. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +``` + +#### Uint64( value ) + +Unsigned 64-bit integer constructor. + +```javascript +var x = new Uint64( 5 ); +// returns +``` + +* * * + +## Properties + +#### Uint64.name + +Static property returning the constructor name. + +```javascript +var str = Uint64.name; +// returns 'Uint64' +``` + +#### Uint64.BYTES_PER_ELEMENT + +Size (in bytes) of the underlying value. + +```javascript +var nbytes = Uint64.BYTES_PER_ELEMENT; +// returns 8 +``` + +#### Uint64.prototype.BYTES_PER_ELEMENT + +Size (in bytes) of the underlying value. + +```javascript +var x = new Uint64( 5 ); + +var nbytes = x.BYTES_PER_ELEMENT; +// returns 8 +``` + +#### Uint64.prototype.byteLength + +Size (in bytes) of the underlying value. + +```javascript +var x = new Uint64( 5 ); + +var nbytes = x.byteLength; +// returns 8 +``` + +#### Uint64.prototype.hi + +High 32-bit word of an unsigned 64-bit integer. + +```javascript +var x = Uint64.from( [ 1234, 5678 ] ); + +var w = x.hi; +// returns 1234 +``` + +#### Uint64.prototype.lo + +Low 32-bit word of an unsigned 64-bit integer. + +```javascript +var x = Uint64.from( [ 1234, 5678 ] ); + +var w = x.lo; +// returns 5678 +``` + +* * * + +## Methods + +### Static Methods + +#### Uint64.from( array ) + +Creates a new unsigned 64-bit integer from an array-like object containing a high and low word. + +```javascript +var x = Uint64.from( [ 1234, 5678 ] ); +// returns +``` + +#### Uint64.of( high, low ) + +Creates a new unsigned 64-bit integer from a high and low word. + +```javascript +var x = Uint64.of( 1234, 5678 ); +// returns +``` + +### Accessor Methods + +These methods do **not** mutate a `Uint64` instance and, instead, return an unsigned 64-bit integer representation. + +#### Uint64.prototype.toString() + +Returns a string representation of a `Uint64` instance. + +```javascript +var x = new Uint64( 5 ); +var str = x.toString(); +// returns '5' +``` + +#### Uint64.prototype.toJSON() + +Returns a [JSON][json] representation of a `Uint64` instance. [`JSON.stringify()`][mdn-json-stringify] implicitly calls this method when stringifying a `Uint64` instance. + +```javascript +var x = new Uint64( 5 ); + +var o = x.toJSON(); +// returns { 'type': 'Uint64', 'words': [ 0, 5 ] } +``` + +To [revive][mdn-json-parse] a `Uint64` instance from a [JSON][json] string, see [@stdlib/number/uint64/reviver][@stdlib/number/uint64/reviver]. + +#### Uint64.prototype.valueOf() + +Converts a `Uint64` instance to a primitive value. + +```javascript +var x = new Uint64( 5 ); + +var v = x.valueOf(); +// e.g., returns +``` + +
+ + + +* * * + + + +
+ +## Notes + +- An unsigned 64-bit integer has a range of \[`0`, `2^64-1`\]. + +
+ + + +* * * + + + +
+ +## Examples + + + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var x = new Uint64( 1234 ); + +console.log( 'type: %s', typeof x ); +// => 'type: object' + +console.log( 'str: %s', x ); +// => 'str: 1234' + +console.log( 'JSON: %s', JSON.stringify( x ) ); +// => 'JSON: {"type":"Uint64","words":[0,1234]}' +``` + +
+ + + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/uint64/ctor/benchmark/benchmark.js new file mode 100644 index 000000000000..e7937da0b8f5 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/benchmark/benchmark.js @@ -0,0 +1,153 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randi = require( '@stdlib/random/base/randi' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64 = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::constructor', pkg ), function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = new Uint64( i ); + if ( typeof z !== 'object' ) { + b.fail( 'should return a Uint64 instance' ); + } + } + b.toc(); + if ( !( z instanceof Uint64 ) ) { + b.fail( 'should return a Uint64 instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::from', pkg ), function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = Uint64.from( [ 0, i ] ); + if ( typeof z !== 'object' ) { + b.fail( 'should return a Uint64 instance' ); + } + } + b.toc(); + if ( !( z instanceof Uint64 ) ) { + b.fail( 'should return a Uint64 instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::of', pkg ), function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = Uint64.of( 0, i ); + if ( typeof z !== 'object' ) { + b.fail( 'should return a Uint64 instance' ); + } + } + b.toc(); + if ( !( z instanceof Uint64 ) ) { + b.fail( 'should return a Uint64 instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:toString', pkg ), function benchmark( b ) { + var o; + var z; + var i; + + z = new Uint64( randi() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.toString(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:toJSON', pkg ), function benchmark( b ) { + var o; + var z; + var i; + + z = new Uint64( randi() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.toJSON(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:valueOf', pkg ), function benchmark( b ) { + var o; + var z; + var i; + + z = new Uint64( randi() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.valueOf(); + if ( typeof o === 'object' ) { + b.fail( 'should not return an object' ); + } + } + b.toc(); + if ( typeof o === 'object' ) { + b.fail( 'should not return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/docs/repl.txt b/lib/node_modules/@stdlib/number/uint64/ctor/docs/repl.txt new file mode 100644 index 000000000000..8cb4753df9f8 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/docs/repl.txt @@ -0,0 +1,153 @@ + +{{alias}}( value ) + Unsigned 64-bit integer constructor. + + Parameters + ---------- + value: number|bigint + Integer value. + + Returns + ------- + v: Uint64 + Unsigned 64-bit integer. + + Examples + -------- + > var x = new {{alias}}( 5 ) + + > x.toString() + '5' + + +{{alias}}.name + Constructor name. + + Examples + -------- + > var str = {{alias}}.name + 'Uint64' + + +{{alias}}.from( words ) + Creates a new unsigned 64-bit integer from an array-like object containing a + high and low word. + + Parameters + ---------- + words: ArrayLikeObject + High and low words. + + Returns + ------- + v: Uint64 + Unsigned 64-bit integer. + + Examples + -------- + > var v = {{alias}}.from( [ 1234, 5678 ] ) + + + +{{alias}}.of( high, low ) + Creates a new unsigned 64-bit integer from a high and low word. + + Parameters + ---------- + high: integer + High word. + + low: integer + Low word. + + Returns + ------- + v: Uint64 + Unsigned 64-bit integer. + + Examples + -------- + > var v = {{alias}}.of( 1234, 5678 ) + + + +{{alias}}.BYTES_PER_ELEMENT + Size (in bytes) of the underlying value. + + Returns + ------- + s: integer + Size (in bytes) of the underlying value. + + Examples + -------- + > var s = {{alias}}.BYTES_PER_ELEMENT + 8 + + +{{alias}}.prototype.BYTES_PER_ELEMENT + Size (in bytes) of the underlying value. + + Returns + ------- + s: integer + Size (in bytes) of the underlying value. + + Examples + -------- + > var x = new {{alias}}( 5 ) + + > var s = x.BYTES_PER_ELEMENT + 8 + + +{{alias}}.prototype.byteLength + Size (in bytes) of the underlying value. + + Returns + ------- + s: integer + Size (in bytes) of the underlying value. + + Examples + -------- + > var x = new {{alias}}( 5 ) + + > var s = x.byteLength + 8 + + +{{alias}}.prototype.hi + Returns the high 32-bit word of an unsigned 64-bit integer. + + Returns + ------- + w: integer + High word. + + Examples + -------- + > var x = {{alias}}.from( [ 1234, 5678 ] ) + + > var w = x.hi + 1234 + + +{{alias}}.prototype.lo + Returns the low 32-bit word of an unsigned 64-bit integer. + + Returns + ------- + w: integer + Low word. + + Examples + -------- + > var x = {{alias}}.from( [ 1234, 5678 ] ) + + > var w = x.lo + 5678 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/uint64/ctor/docs/types/index.d.ts new file mode 100644 index 000000000000..eeacf5249496 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/docs/types/index.d.ts @@ -0,0 +1,185 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +interface SerializedUint64 { + /** + * Type name identifying the serialized value. + */ + type: 'Uint64'; + + /** + * Array containing the high and low 32-bit words. + */ + words: [ number, number ]; +} + +/** +* Unsigned 64-bit integer. +*/ +declare class Uint64 { + /** + * Unsigned 64-bit integer constructor. + * + * @param value - integer value + * @returns unsigned 64-bit integer + * + * @example + * var x = new Uint64( 5 ); + * // returns + */ + constructor( value: number | bigint ); + + /** + * Creates a new unsigned 64-bit integer from an array-like object containing a high and low word. + * + * @param words - high and low words + * @returns unsigned 64-bit integer + * + * @example + * var x = Uint64.from( [ 1234, 5678 ] ); + * // returns + */ + static from( words: ArrayLike ): Uint64; + + /** + * Creates a new unsigned 64-bit integer from a high and low word. + * + * @param high - high word + * @param low - low word + * @returns unsigned 64-bit integer + * + * @example + * var x = Uint64.of( 1234, 5678 ); + * // returns + */ + static of( high: number, low: number ): Uint64; + + /** + * Size (in bytes) of the underlying value. + * + * @returns size in bytes + * + * @example + * var nbytes = Uint64.BYTES_PER_ELEMENT; + * // returns 8 + */ + static readonly BYTES_PER_ELEMENT: 8; + + /** + * Size (in bytes) of the underlying value. + * + * @returns size in bytes + * + * @example + * var x = new Uint64( 5 ); + * + * var nbytes = x.BYTES_PER_ELEMENT; + * // returns 8 + */ + readonly BYTES_PER_ELEMENT: 8; + + /** + * Size (in bytes) of the underlying value. + * + * @returns size of the underlying value. + * + * @example + * var v = new Uint64( 5 ); + * + * var nbytes = v.byteLength; + * // returns 8 + */ + readonly byteLength: 8; + + /** + * Returns the high 32-bit word of an unsigned 64-bit integer. + * + * @returns high 32-bit word + * + * @example + * var x = Uint64.from( [ 1, 2 ] ); + * + * var w = x.hi; + * // returns 1 + */ + readonly hi: number; + + /** + * Returns the low 32-bit word of an unsigned 64-bit integer. + * + * @returns low 32-bit word + * + * @example + * var x = Uint64.from( [ 1, 2 ] ); + * + * var w = x.lo; + * // returns 2 + */ + readonly lo: number; + + /** + * Serializes an unsigned 64-bit integer as a string. + * + * @param radix - radix (base) to use for string conversion (2-36) + * @returns serialized unsigned 64-bit integer + * + * @example + * var x = new Uint64( 5 ); + * + * var str = x.toString(); + * // returns '5' + */ + toString( radix?: number ): string; + + /** + * Serializes an unsigned 64-bit integer as a JSON object. + * + * ## Notes + * + * - `JSON.stringify()` implicitly calls this method when stringifying a `Uint64` instance. + * + * + * @returns serialized unsigned 64-bit integer + * + * @example + * var x = new Uint64( 5 ); + * + * var obj = x.toJSON(); + * // returns { 'type': 'Uint64', 'words': [ 0, 5 ] } + */ + toJSON(): SerializedUint64; + + /** + * Converts an unsigned 64-bit integer to a primitive value. + * + * @returns primitive value + * + * @example + * var x = new Uint64( 5 ); + * + * var v = x.valueOf(); + * // e.g., returns + */ + valueOf(): number | bigint; +} + +// EXPORTS // + +export = Uint64; diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/docs/types/test.ts b/lib/node_modules/@stdlib/number/uint64/ctor/docs/types/test.ts new file mode 100644 index 000000000000..412e37bf2104 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/docs/types/test.ts @@ -0,0 +1,73 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import Uint64 = require( './index' ); + + +// TESTS // + +// The function returns a Unsigned 64-bit integer with the expected properties... +{ + const x = new Uint64( 5 ); // $ExpectType Uint64 + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.hi; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.lo; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.BYTES_PER_ELEMENT; // $ExpectType 8 + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.byteLength; // $ExpectType 8 +} + +// Unsigned 64-bit integer comes with a `toString` method to serialize an instance as a string... +{ + const x = new Uint64( 5 ); // $ExpectType Uint64 + + x.toString(); // $ExpectType string +} + +// Unsigned 64-bit integer comes with a `toJSON` method to serialize an instance as a JSON object.... +{ + const x = new Uint64( 5 ); // $ExpectType Uint64 + + x.toJSON(); // $ExpectType SerializedUint64 +} + +// Unsigned 64-bit integer comes with a `valueOf` method to serialize an instance to a primitive value... +{ + const x = new Uint64( 5 ); // $ExpectType Uint64 + + x.valueOf(); // $ExpectType number | bigint +} + +// The compiler throws an error if the constructor is invoked without the `new` keyword... +{ + Uint64( 5 ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided an unsupported number of arguments... +{ + new Uint64(); // $ExpectError + new Uint64( 5, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/examples/index.js b/lib/node_modules/@stdlib/number/uint64/ctor/examples/index.js new file mode 100644 index 000000000000..92dee527cf3a --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/examples/index.js @@ -0,0 +1,32 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Uint64 = require( './../lib' ); + +var x = new Uint64( 1234 ); + +console.log( 'type: %s', typeof x ); +// => 'type: object' + +console.log( 'str: %s', x ); +// => 'str: 1234' + +console.log( 'JSON: %s', JSON.stringify( x ) ); +// => 'JSON: {"type":"Uint64","words":[0,1234]}' diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/lib/index.js b/lib/node_modules/@stdlib/number/uint64/ctor/lib/index.js new file mode 100644 index 000000000000..34c9e26b59a8 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Unsigned 64-bit integer constructor. +* +* @module @stdlib/number/uint64/ctor +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var x = new Uint64( 5 ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/lib/indices.js b/lib/node_modules/@stdlib/number/uint64/ctor/lib/indices.js new file mode 100644 index 000000000000..57341d75b278 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/lib/indices.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isLittleEndian = require( '@stdlib/assert/is-little-endian' ); + + +// MAIN // + +var indices; +var HIGH; +var LOW; + +if ( isLittleEndian === true ) { + HIGH = 1; // second index + LOW = 0; // first index +} else { + HIGH = 0; // first index + LOW = 1; // second index +} +indices = { + 'HIGH': HIGH, + 'LOW': LOW +}; + + +// EXPORTS // + +module.exports = indices; diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/lib/main.js b/lib/node_modules/@stdlib/number/uint64/ctor/lib/main.js new file mode 100644 index 000000000000..601bf25365ad --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/lib/main.js @@ -0,0 +1,345 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable max-len, no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isUint32Array = require( '@stdlib/assert/is-uint32array' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isBigInt = require( '@stdlib/assert/is-bigint' ).isPrimitive; +var isCollection = require( '@stdlib/assert/is-collection' ); +var isBetween = require( '@stdlib/assert/is-between' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var join = require( '@stdlib/array/base/join' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); +var format = require( '@stdlib/string/format' ); +var indices = require( './indices.js' ); +var int2str = require( './to_string.js' ); + + +// VARIABLES // + +var HAS_BIGINT = hasBigIntSupport(); +var TWO_32 = 0x100000000; // 2^32 + + +// MAIN // + +/** +* Unsigned 64-bit integer constructor. +* +* @constructor +* @param {(NonNegativeInteger|bigint)} value - integer value +* @throws {TypeError} must invoke using the `new` keyword +* @throws {TypeError} must provide a number on the interval [0, 2^64] +* @returns {Uint64} unsigned 64-bit integer +* +* @example +* var v = new Uint64( 5 ); +* // returns +*/ +function Uint64( value ) { + var buffer; + var v; + if ( !( this instanceof Uint64 ) ) { + throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' ); + } + buffer = new Uint32Array( 2 ); + if ( isBigInt( value ) ) { + v = BigInt.asUintN( 64, value ); + if ( v !== value ) { + throw new TypeError( format( 'invalid argument. Must provide an integer on the interval [0, 2^64-1]. Value: `%s`.', value ) ); + } + buffer[ indices.HIGH ] = v >> BigInt( 32 ); + buffer[ indices.LOW ] = v & BigInt( UINT32_MAX ); + } else if ( isInteger( value ) && isBetween( value, 0, MAX_SAFE_INTEGER ) ) { + buffer[ indices.HIGH ] = ( value / TWO_32 ) >>> 0; + buffer[ indices.LOW ] = value >>> 0; + } else { + throw new TypeError( format( 'invalid argument. Must provide an integer on the interval [0, 2^53-1]. Value: `%s`.', value ) ); + } + setReadOnly( this, '_buffer', buffer ); + return this; +} + +/** +* Constructor name. +* +* @name name +* @memberof Uint64 +* @readonly +* @type {string} +* @default 'Uint64' +* +* @example +* var name = Uint64.name; +* // returns 'Uint64' +*/ +setReadOnly( Uint64, 'name', 'Uint64' ); + +/** +* Creates a new unsigned 64-bit integer from an array-like object containing a high and low word. +* +* @name from +* @memberof Uint64 +* @type {Function} +* @param {Collection} words - high and low words +* @throws {TypeError} must provide an array-like object containing two elements +* @returns {Uint64} unsigned 64-bit integer +* +* @example +* var x = Uint64.from( [ 1234, 5678 ] ); +* // returns +*/ +setReadOnly( Uint64, 'from', function fromWords( words ) { + var v; + if ( !isCollection( words ) ) { + throw new TypeError( format( 'invalid argument. Must provide an array. Value: `%s`.', words ) ); + } + if ( words.length !== 2 ) { + throw new TypeError( format( 'invalid argument. Must provide an array of length 2. Value: `[%s]`.', join( words, ',' ) ) ); + } + v = new Uint64( 0 ); + if ( isUint32Array( words ) ) { + v._buffer[ indices.HIGH ] = words[ 0 ]; // eslint-disable-line no-underscore-dangle + v._buffer[ indices.LOW ] = words[ 1 ]; // eslint-disable-line no-underscore-dangle + return v; + } + + // TODO: consider supporting any iterable object + + if ( + isInteger( words[ 0 ] ) && + isInteger( words[ 1 ] ) && + isBetween( words[ 0 ], 0, UINT32_MAX ) && + isBetween( words[ 1 ], 0, UINT32_MAX ) + ) { + // TODO: consider whether we should support accessor arrays here + v._buffer[ indices.HIGH ] = words[ 0 ]; // eslint-disable-line no-underscore-dangle + v._buffer[ indices.LOW ] = words[ 1 ]; // eslint-disable-line no-underscore-dangle + return v; + } + throw new TypeError( format( 'invalid argument. Must provide an array of integer values on the interval [%u, %u]. Value: `[%s]`.', 0, UINT32_MAX, join( words, ', ' ) ) ); +}); + +/** +* Creates a new unsigned 64-bit integer from a high and low word. +* +* @name of +* @memberof Uint64 +* @type {Function} +* @param {NonNegativeInteger} high - high word +* @param {NonNegativeInteger} low - low word +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a nonnegative integer +* @returns {Uint64} unsigned 64-bit integer +* +* @example +* var x = Uint64.of( 1234, 5678 ); +* // returns +*/ +setReadOnly( Uint64, 'of', function of( high, low ) { + var v; + if ( !isInteger( high ) || !isBetween( high, 0, UINT32_MAX ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer on the interval [%u, %u]. Value: `%s`.', 0, UINT32_MAX, high ) ); + } + if ( !isInteger( low ) || !isBetween( low, 0, UINT32_MAX ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer on the interval [%u, %u]. Value: `%s`.', 0, UINT32_MAX, low ) ); + } + v = new Uint64( 0 ); + v._buffer[ indices.HIGH ] = high; // eslint-disable-line no-underscore-dangle + v._buffer[ indices.LOW ] = low; // eslint-disable-line no-underscore-dangle + return v; +}); + +/** +* Size (in bytes) of the underlying value. +* +* @name BYTES_PER_ELEMENT +* @memberof Uint64 +* @type {integer} +* @returns {integer} size in bytes +* +* @example +* var nbytes = Uint64.BYTES_PER_ELEMENT; +* // returns 8 +*/ +setReadOnly( Uint64, 'BYTES_PER_ELEMENT', 8 ); + +/** +* Size (in bytes) of the underlying value. +* +* @name BYTES_PER_ELEMENT +* @memberof Uint64.prototype +* @type {integer} +* @returns {integer} size in bytes +* +* @example +* var x = new Uint64( 5 ); +* +* var nbytes = x.BYTES_PER_ELEMENT; +* // returns 8 +*/ +setReadOnly( Uint64.prototype, 'BYTES_PER_ELEMENT', 8 ); + +/** +* Size (in bytes) of the underlying value. +* +* @name byteLength +* @memberof Uint64.prototype +* @type {integer} +* @returns {integer} size in bytes +* +* @example +* var x = new Uint64( 5 ); +* +* var nbytes = x.byteLength; +* // returns 8 +*/ +setReadOnly( Uint64.prototype, 'byteLength', 8 ); + +/** +* Returns the high 32-bit word of an unsigned 64-bit integer. +* +* @name hi +* @memberof Uint64.prototype +* @type {uinteger} +* @returns {uinteger} 32-bit unsigned integer +* +* @example +* var x = Uint64.from( [ 1234, 5678 ] ); +* +* var w = x.hi; +* // returns 1234 +*/ +setReadOnlyAccessor( Uint64.prototype, 'hi', function getHighWord() { + return this._buffer[ indices.HIGH ]; +}); + +/** +* Returns the low 32-bit word of an unsigned 64-bit integer. +* +* @name lo +* @memberof Uint64.prototype +* @type {uinteger} +* @returns {uinteger} 32-bit unsigned integer +* +* @example +* var x = Uint64.from( [ 1234, 5678 ] ); +* +* var w = x.lo; +* // returns 5678 +*/ +setReadOnlyAccessor( Uint64.prototype, 'lo', function getLowWord() { + return this._buffer[ indices.LOW ]; +}); + +/** +* Serializes an unsigned 64-bit integer as a string. +* +* @name toString +* @memberof Uint64.prototype +* @type {Function} +* @param {PositiveInteger} [radix=10] - radix (base) to use for string conversion (2-36) +* @throws {TypeError} must provide an integer on the interval [2,36] +* @returns {string} serialized unsigned 64-bit integer +* +* @example +* var str = new Uint64( 5 ).toString(); +* // returns '5' +* +* str = Uint64.from( [ 1, 0 ] ).toString(); +* // returns '4294967296' +* +* str = new Uint64( 100000000001 ).toString(); +* // returns '100000000001' +* +*/ +setReadOnly( Uint64.prototype, 'toString', function toString( radix ) { + var rad; + if ( arguments.length < 1 ) { + rad = 10; + } else if ( isInteger( radix ) && isBetween( radix, 2, 36 ) ) { + rad = radix; + } else { + throw new TypeError( format( 'invalid argument. Must provide an integer on the interval [%d, %d]. Value: `%s`.', 2, 36, radix ) ); + } + if ( HAS_BIGINT ) { + return BigInt( this.valueOf() ).toString( rad ); + } + return int2str( [ this.hi, this.lo ], rad ); +}); + +/** +* Serializes an unsigned 64-bit integer as a JSON object. +* +* ## Notes +* +* - `JSON.stringify()` implicitly calls this method when stringifying a `Uint64` instance. +* +* @name toJSON +* @memberof Uint64.prototype +* @type {Function} +* @returns {Object} serialized unsigned 64-bit integer +* +* @example +* var x = new Uint64( 5 ); +* +* var y = x.toJSON(); +* // returns { 'type': 'Uint64', 'words': [ 0, 5 ] } +*/ +setReadOnly( Uint64.prototype, 'toJSON', function toJSON() { + return { + 'type': 'Uint64', + 'words': [ this.hi, this.lo ] + }; +}); + +/** +* Converts an unsigned 64-bit integer to a primitive value. +* +* @name valueOf +* @memberof Uint64.prototype +* @type {Function} +* @returns {(number|bigint)} primitive value +* +* @example +* var x = new Uint64( 5 ); +* +* var v = x.valueOf(); +* // e.g., returns +*/ +setReadOnly( Uint64.prototype, 'valueOf', function valueOf() { + if ( HAS_BIGINT ) { + return ( BigInt( this._buffer[ indices.HIGH ] ) << BigInt( 32 ) ) | BigInt( this._buffer[ indices.LOW ] ); + } + return ( this._buffer[ indices.HIGH ] * TWO_32 ) + this._buffer[ indices.LOW ]; +}); + + +// EXPORTS // + +module.exports = Uint64; diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/lib/to_string.js b/lib/node_modules/@stdlib/number/uint64/ctor/lib/to_string.js new file mode 100644 index 000000000000..05ce53e86d90 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/lib/to_string.js @@ -0,0 +1,170 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var Uint32Array = require( '@stdlib/array/uint32' ); +var lpad = require( '@stdlib/string/left-pad' ); + + +// VARIABLES // + +var TWO_32 = 0x100000000; // 2^32 +var TWO_16 = 0x10000; // 2^16 + +/* eslint-disable array-element-newline */ + +var POWERMAP = [ + // , // radix + 32, 4294967296, // 2 + 20, 3486784401, // 3 + 16, 4294967296, // 4 + 13, 1220703125, // 5 + 12, 2176782336, // 6 + 11, 1977326743, // 7 + 10, 1073741824, // 8 + 10, 3486784401, // 9 + 9, 1000000000, // 10 + 9, 2357947691, // 11 + 8, 429981696, // 12 + 8, 815730721, // 13 + 8, 1475789056, // 14 + 8, 2562890625, // 15 + 8, 4294967296, // 16 + 7, 410338673, // 17 + 7, 612220032, // 18 + 7, 893871739, // 19 + 7, 1280000000, // 20 + 7, 1801088541, // 21 + 7, 2494357888, // 22 + 7, 3404825447, // 23 + 6, 191102976, // 24 + 6, 244140625, // 25 + 6, 308915776, // 26 + 6, 387420489, // 27 + 6, 481890304, // 28 + 6, 594823321, // 29 + 6, 729000000, // 30 + 6, 887503681, // 31 + 6, 1073741824, // 32 + 6, 1291467969, // 33 + 6, 1544804416, // 34 + 6, 1838265625, // 35 + 6, 2176782336 // 36 +]; + +/* eslint-enable array-element-newline */ + +var WORKSPACE = new Uint32Array( 2 ); + + +// FUNCTIONS // + +/** +* Performs division and modulo for an unsigned 64-bit integer represented as high-low words. +* +* ## Notes +* +* - The output array contains the following elements upon return: `[ quotient, remainder ]`. +* +* @private +* @param {Uint32Array} words - 32-bit words +* @param {PositiveInteger} divisor - positive integer close to `2^32` +* @param {Uint32Array} out - output array +* @returns {Uint32Array} output array +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = new Uint32Array( 2 ); +* var x = chunkedDivMod( [ 1, 0 ], 1e9, out ); +* // returns [ 4, 294967296 ] +*/ +function chunkedDivMod( words, divisor, out ) { + var high; + var low; + var quo; + var rem; + var qrd; + + if ( divisor === TWO_32 ) { + out[ 0 ] = words[ 0 ]; + out[ 1 ] = words[ 1 ]; + return out; + } + high = words[ 0 ] >>> 0; + low = words[ 1 ] >>> 0; + quo = ( high / divisor ) >>> 0; + rem = high - ( divisor * quo ); + + rem = ( rem * TWO_16 ) + ( low >>> 16 ); + qrd = ( rem / divisor ) >>> 0; + quo = ( quo * TWO_16 ) + qrd; + rem -= divisor * qrd; + + rem = ( rem * TWO_16 ) + ( low & 0xffff ); + qrd = ( rem / divisor ) >>> 0; + quo = ( quo * TWO_16 ) + qrd; + rem -= divisor * qrd; + + out[ 0 ] = quo; + out[ 1 ] = rem; + return out; +} + + +// MAIN // + +/** +* Serializes an unsigned 64-bit integer as a string in the specified base. +* +* @private +* @param {Uint32Array} words - high and low words +* @param {PositiveInteger} radix - radix (base) to use for string conversion +* @returns {string} serialized unsigned 64-bit integer +*/ +function int2str( words, radix ) { + var quo; + var rem; + var idx; + + // Reset the workspace: + WORKSPACE[ 0 ] = 0; + WORKSPACE[ 1 ] = 0; + + // Compute the index into a pre-computed strided table: + idx = ( radix-2 ) * 2; + + // Use a pre-computed table to select a divisor (chosen to be a power of the radix closest to 2^32, but more generally works for 2^11 to 2^37) and a chunk size for efficient base conversion... + chunkedDivMod( words, POWERMAP[ idx+1 ], WORKSPACE ); + quo = WORKSPACE[ 0 ].toString( radix ); + rem = WORKSPACE[ 1 ].toString( radix ); + if ( quo === '0' ) { + quo = ''; + } else { + rem = lpad( rem, POWERMAP[ idx ], '0' ); + } + return quo + rem; +} + + +// EXPORTS // + +module.exports = int2str; diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/package.json b/lib/node_modules/@stdlib/number/uint64/ctor/package.json new file mode 100644 index 000000000000..b7753d345528 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/number/uint64/ctor", + "version": "0.0.0", + "description": "Unsigned 64-bit integer.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "constructor", + "ctor", + "uint64", + "unsigned", + "64-bit", + "integer", + "int" + ] +} diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/test/test.from.js b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.from.js new file mode 100644 index 000000000000..ec623b28a45e --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.from.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Uint64 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a read-only `from` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64, 'from' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64.from ), true, 'has method' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Uint64.from = null; + } +}); + +tape( 'the method throws an error if not provided an array-like object containing two 32-bit words', function test( t ) { + var values; + var i; + + values = [ + null, + void 0, + true, + false, + [], + {}, + function noop() {}, + 'foo', + 0, + [ 1 ], + [ 1, 2, 3 ], + [ 0, -1 ], + [ 0, UINT32_MAX + 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var x = Uint64.from( value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the method returns an unsigned 64-bit integer', function test( t ) { + var x; + + x = Uint64.from( [ 0, 1 ] ); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + + x = Uint64.from( [ UINT32_MAX, UINT32_MAX ] ); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + + x = Uint64.from( new Uint32Array( [ 0, 1 ] ) ); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + + x = Uint64.from({ + '0': 10, + '1': 20, + 'length': 2 + }); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/test/test.js b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.js new file mode 100644 index 000000000000..741f4899c313 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.js @@ -0,0 +1,255 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64 = require( './../lib' ); + + +// VARIABLES // + +var HAS_BIGINT = hasBigIntSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var x = new Uint64( 5 ); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor requires the `new` keyword', function test( t ) { + var ctor = Uint64; + t.throws( foo, TypeError, 'throws an error' ); + t.end(); + + function foo() { + ctor( 5 ); + } +}); + +tape( 'the constructor throws an error if not provided a number or BigInt', function test( t ) { + var values; + var i; + + values = [ + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var x = new Uint64( value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor throws an error if provided an invalid/unsupported number', function test( t ) { + var values; + var i; + + values = [ + -1, + 0.5, + 1 + MAX_SAFE_INTEGER + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + + t.end(); + + function badValue( value ) { + return function badValue() { + var x = new Uint64( value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor throws an error if provided an invalid/unsupported BigInt', function test( t ) { + var values; + var i; + + if ( !HAS_BIGINT ) { + t.end(); + return; + } + + values = [ + BigInt( -1 ), + BigInt( 1 ) << BigInt( 64 ) // 2^64 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + + t.end(); + + function badValue( value ) { + return function badValue() { + var x = new Uint64( value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor has a read-only `name` property', function test( t ) { + t.strictEqual( hasOwnProp( Uint64, 'name' ), true, 'has property' ); + t.strictEqual( Uint64.name, 'Uint64', 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Uint64.name = 'Foo'; + } +}); + +tape( 'the constructor has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { + t.strictEqual( hasOwnProp( Uint64, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Uint64.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Uint64.BYTES_PER_ELEMENT = 4; + } +}); + +tape( 'the constructor prototype has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { + t.strictEqual( hasOwnProp( Uint64.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Uint64.prototype.BYTES_PER_ELEMENT, 8, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Uint64.prototype.BYTES_PER_ELEMENT = 4; + } +}); + +tape( 'the constructor prototype has a read-only `byteLength` property', function test( t ) { + t.strictEqual( hasOwnProp( Uint64.prototype, 'byteLength' ), true, 'has property' ); + t.strictEqual( Uint64.prototype.byteLength, 8, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Uint64.prototype.byteLength = 4; + } +}); + +tape( 'the constructor returns an instance having a read-only `hi` property for getting the high word', function test( t ) { + var x = new Uint64.from( [ 1, 0 ] ); + + t.strictEqual( x.hi, 1, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + x.hi = 4; + } +}); + +tape( 'the constructor returns an instance having a read-only `lo` property for getting the low word', function test( t ) { + var x = new Uint64.from( [ 1, 0 ] ); + + t.strictEqual( x.lo, 0, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + x.lo = 4; + } +}); + +tape( 'the constructor returns an instance which supports serializing an instance as a JSON object', function test( t ) { + var expected; + var x; + + x = new Uint64( 5 ); + expected = { + 'type': 'Uint64', + 'words': [ 0, 5 ] + }; + t.deepEqual( x.toJSON(), expected, 'returns expected value' ); + t.strictEqual( JSON.stringify( x ), JSON.stringify( expected ), 'returns expected value' ); + + x = new Uint64.from( [ 1, 0 ] ); + expected = { + 'type': 'Uint64', + 'words': [ 1, 0 ] + }; + t.deepEqual( x.toJSON(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which supports converting an instance to a primitive value', function test( t ) { + var x; + + if ( HAS_BIGINT ) { + x = new Uint64( 5 ); + t.strictEqual( x.valueOf(), BigInt( 5 ), 'returns expected value' ); + + x = Uint64.from( [ 0xDEADBEEF, 0xBADF00D0 ] ); + t.strictEqual( x.valueOf(), BigInt( '0xDEADBEEFBADF00D0' ), 'returns expected value' ); + + x = Uint64.from( [ 0xDEADBEEF, 0xBADF00D1 ] ); + t.strictEqual( x.valueOf(), BigInt( '0xDEADBEEFBADF00D1' ), 'returns expected value' ); + + x = Uint64.from( [ 0xDEADBEEF, 0xBADF00D2 ] ); + t.strictEqual( x.valueOf(), BigInt( '0xDEADBEEFBADF00D2' ), 'returns expected value' ); + } + else { + x = new Uint64( 5 ); + t.strictEqual( x.valueOf(), 5, 'returns expected value' ); + + x = Uint64.from( [ 0xDEADBEEF, 0xBADF00D0 ] ); + t.strictEqual( x.valueOf(), Number( '0xDEADBEEFBADF00D0' ), 'returns expected value' ); + + x = Uint64.from( [ 0xDEADBEEF, 0xBADF00D1 ] ); + t.strictEqual( x.valueOf(), Number( '0xDEADBEEFBADF00D1' ), 'returns expected value' ); + + x = Uint64.from( [ 0xDEADBEEF, 0xBADF00D2 ] ); + t.strictEqual( x.valueOf(), Number( '0xDEADBEEFBADF00D2' ), 'returns expected value' ); + } + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/test/test.of.js b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.of.js new file mode 100644 index 000000000000..2de6b0123ab4 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.of.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var Uint64 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a read-only `of` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64, 'of' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64.of ), true, 'has method' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Uint64.of = null; + } +}); + +tape( 'the method throws an error if not provided two unsigned 32-bit integers', function test( t ) { + var values; + var i; + + values = [ + [ 0, null ], + [ 0, void 0 ], + [ 0, true ], + [ 0, false ], + [ 0, [] ], + [ 0, {} ], + [ 0, function noop() {} ], + [ 0, 'foo' ], + [ 0, -1 ], + [ 0, UINT32_MAX + 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), TypeError, format( 'throws an error when provided %s, %s', values[i][0], values[i][1] ) ); + t.throws( badValue( values[i][1], values[i][0] ), TypeError, format( 'throws an error when provided %s, %s', values[i][1], values[i][0] ) ); + } + t.end(); + + function badValue( value1, value2 ) { + return function badValue() { + var x = Uint64.of( value1, value2 ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the method returns an unsigned 64-bit integer', function test( t ) { + var x; + + x = Uint64.of( 0, 1 ); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + + x = Uint64.of( UINT32_MAX, UINT32_MAX ); + t.strictEqual( x instanceof Uint64, true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/ctor/test/test.to_string.js b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.to_string.js new file mode 100644 index 000000000000..17892ae7d22a --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/ctor/test/test.to_string.js @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var Uint64 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toString` method for serializing an instance as a string', function test( t ) { + var x; + + x = new Uint64( 5 ); + t.strictEqual( x.toString(), '5', 'returns expected value' ); + + x = new Uint64.from( [ 1, 0 ] ); + t.strictEqual( x.toString(), '4294967296', 'returns expected value' ); + + t.end(); +}); + +tape( 'the method accepts a radix parameter for serializing an instance as a string in bases 2 through 36', function test( t ) { + var values; + var radix; + var i; + var x; + var z; + + values = [ + 0, + 1, + 2, + 3, + 5, + 7, + 11, + 97, + 101, + 997, + 1009, + UINT32_MAX, + UINT32_MAX + 1, + MAX_SAFE_INTEGER - 1, + MAX_SAFE_INTEGER + ]; + + for ( i = 0; i < values.length; i++ ) { + z = values[i]; + x = new Uint64( z ); + + for ( radix = 2; radix <= 36; radix++ ) { + t.strictEqual( x.toString( radix ), z.toString( radix ), 'returns expected value' ); + } + } + t.end(); +}); + +tape( 'the method throws an error if provided an invalid radix', function test( t ) { + var values; + var i; + var x; + + x = new Uint64( 5 ); + + values = [ + 0, + 1, + 37, + -1, + 2.5, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var y = x.toString( value ); // eslint-disable-line no-unused-vars + }; + } +});