diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/README.md b/lib/node_modules/@stdlib/number/uint64/base/add/README.md new file mode 100644 index 000000000000..e45c7dc2b4fd --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/README.md @@ -0,0 +1,155 @@ + + +# add + +> Add two unsigned 64-bit integers. + +
+ +
+ + + +
+ +## Usage + +```javascript +var add = require( '@stdlib/number/uint64/base/add' ); +``` + +#### add( a, b ) + +Adds two unsigned 64-bit integers. + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); + +var a = new Uint64( 5 ); +var b = new Uint64( 10 ); + +var v = add( a, b ); +// returns [ 15n ] +``` + +#### add.assign( ah, al, bh, bl, out, so, oo ) + +Adds two unsigned 64-bit integers and assigns results to a provided output array. + +```javascript +var Uint32Array = require( '@stdlib/array/uint32' ); + +var out = new Uint32Array( 2 ); +var v = add.assign( 0, 5, 0, 10, out, 1, 0 ); +// returns [ 0, 15 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **ah**: high 32-bit word of the first unsigned 64-bit integer. +- **al**: low 32-bit word of the first unsigned 64-bit integer. +- **bh**: high 32-bit word of the second unsigned 64-bit integer. +- **bl**: low 32-bit word of the second unsigned 64-bit integer. +- **out**: output array. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + +#### add.strided( a, sa, oa, b, sb, ob, out, so, oo ) + +Adds two unsigned 64-bit integers stored in integer-valued strided array views and assigns results to a provided strided output array. + +```javascript +var Uint32Array = require( '@stdlib/array/uint32' ); + +var a = new Uint32Array( [ 0, 5 ] ); +var b = new Uint32Array( [ 0, 10 ] ); +var out = new Uint32Array( 2 ); + +var v = add.strided( a, 1, 0, b, 1, 0, out, 1, 0 ); +// returns [ 0, 15 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **a**: first unsigned 64-bit integer strided array view. +- **sa**: stride length for `a`. +- **oa**: starting index for `a`. +- **b**: second unsigned 64-bit integer strided array view. +- **sb**: stride length for `b`. +- **ob**: starting index for `b`. +- **out**: output array. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + +
+ + + +
+ +## Examples + + + +```javascript +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var add = require( '@stdlib/number/uint64/base/add' ); + +var a = new Uint64( 5 ); +var b = new Uint64( 10 ); +var v = add( a, b ); +// returns [ 15n ] + +a = new Uint64( 1234567890 ); +b = new Uint64( 8765432109 ); +v = add( a, b ); +// returns [ 9999999999n ] +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/uint64/base/add/benchmark/benchmark.js new file mode 100644 index 000000000000..2b6fc2772035 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/benchmark/benchmark.js @@ -0,0 +1,128 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var add = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'uint32' +}; + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var x; + var y; + var z; + var i; + + x = discreteUniform( 100, 0, UINT32_MAX, options); + values = []; + for ( i = 0; i < x.length; i++ ) { + values.push( Uint64.of( x[i], x[(i+1)%x.length] ) ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = values[i%values.length]; + z = values[(i+1)%values.length]; + out = add( y, z ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !( out instanceof Uint64 ) ) { + b.fail( 'should return a Uint64 instance' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:assign', pkg ), function benchmark( b ) { + var out; + var N; + var x; + var i; + + N = 100; + x = discreteUniform( N, 0, UINT32_MAX, options); + + out = new Uint32Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // eslint-disable-next-line max-len + out = add.assign( x[i%N], x[(i+1)%N], x[(i+2)%N], x[(i+3)%N], out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !( out instanceof Uint32Array ) ) { + b.fail( 'should return a Uint32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:strided', pkg ), function benchmark( b ) { + var out; + var N; + var x; + var y; + var i; + var j; + + N = 50; + x = discreteUniform( N*2, 0, UINT32_MAX, options); + y = discreteUniform( N*2, 0, UINT32_MAX, options); + + out = new Uint32Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = ( i % N ) * 2; + out = add.strided( x, 1, j, y, 1, j, out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !( out instanceof Uint32Array ) ) { + b.fail( 'should return a Uint32Array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/docs/repl.txt b/lib/node_modules/@stdlib/number/uint64/base/add/docs/repl.txt new file mode 100644 index 000000000000..5bc956ae0a90 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/docs/repl.txt @@ -0,0 +1,116 @@ + +{{alias}}( a, b ) + Adds two unsigned 64-bit integers. + + Parameters + ---------- + a: Uint64 + Unsigned 64-bit integer. + + b: Uint64 + Unsigned 64-bit integer. + + Returns + ------- + out: Uint64 + Result. + + Examples + -------- + > var a = new {{alias:@stdlib/number/uint64/ctor}}( 5 ) + [ 5n ] + > var b = new {{alias:@stdlib/number/uint64/ctor}}( 10 ) + [ 10n ] + > var out = {{alias}}( a, b ) + [ 15n ] + + +{{alias}}.assign( ah, al, bh, bl, out, so, oo ) + Adds two unsigned 64-bit integers and assigns results + to a provided output array. + + Parameters + ---------- + ah: number + High 32-bit word of the first unsigned 64-bit integer. + + al: number + Low 32-bit word of the first unsigned 64-bit integer. + + bh: number + High 32-bit word of the second unsigned 64-bit integer. + + bl: number + Low 32-bit word of the second unsigned 64-bit integer. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length. + + oo: integer + Starting index. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var out = new {{alias:@stdlib/array/uint32}}( 2 ); + > {{alias}}.assign( 1, 2, 3, 4, out, 1, 0 ) + [ 4, 6 ] + + +{{alias}}.strided( a, sa, oa, b, sb, ob, out, so, oo ) + Adds two unsigned 64-bit integers stored in integer- + valued strided array views and assigns results to a + provided strided output array. + + Parameters + ---------- + a: ArrayLikeObject + First unsigned 64-bit integer view. + + sa: integer + Stride length for `a`. + + oa: integer + Starting index for `a`. + + b: ArrayLikeObject + Second unsigned 64-bit integer view. + + sb: integer + Stride length for `b`. + + ob: integer + Starting index for `b`. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var a = new {{alias:@stdlib/array/uint32}}( [ 1, 2 ] ); + > var b = new {{alias:@stdlib/array/uint32}}( [ 3, 4 ] ); + > var out = new {{alias:@stdlib/array/uint32}}( 2 ); + > {{alias}}.strided( a, 1, 0, b, 1, 0, out, 1, 0 ) + [ 4, 6 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/uint64/base/add/docs/types/index.d.ts new file mode 100644 index 000000000000..879e66397d12 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/docs/types/index.d.ts @@ -0,0 +1,130 @@ +/* +* @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 + +/// + +import { Uint64 } from '@stdlib/types/number'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for adding two unsigned 64-bit integers. +*/ +interface Add { + /** + * Adds two unsigned 64-bit integers. + * + * @param a - unsigned 64-bit integer + * @param b - unsigned 64-bit integer + * @returns result + * + * @example + * var Uint64 = require( '@stdlib/number/uint64/ctor' ); + * + * var a = new Uint64( 5 ); + * var b = new Uint64( 10 ); + * + * var v = add( a, b ); + * // returns [ 15n ] + */ + ( a: Uint64, b: Uint64 ): Uint64; + + /** + * Adds two unsigned 64-bit integers and assigns results to a provided output array. + * + * @param ah - high 32-bit word of the first unsigned 64-bit integer + * @param al - low 32-bit word of the first unsigned 64-bit integer + * @param bh - high 32-bit word of the second unsigned 64-bit integer + * @param bl - low 32-bit word of the second unsigned 64-bit integer + * @param out - output array + * @param so - stride length + * @param oo - starting index + * @returns output array + * + * @example + * var Uint32Array = require( '@stdlib/array/uint32' ); + * + * var out = add.assign( 0, 5, 0, 10, new Uint32Array( 2 ), 1, 0 ); + * // returns [ 0, 15 ] + */ + assign>( ah: number, al: number, bh: number, bl: number, out: T, so: number, oo: number ): T; + + /** + * Adds two unsigned 64-bit integers stored in integer-valued strided array views and assigns results to a provided strided output array. + * + * @param a - first unsigned 64-bit integers + * @param sa - stride length for `a` + * @param oa - starting index for `a` + * @param b - second unsigned 64-bit integers + * @param sb - stride length for `b` + * @param ob - starting index for `b` + * @param out - output array + * @param so - stride length for `out` + * @param oo - starting index for `out` + * @returns output array + * + * @example + * var Uint32Array = require( '@stdlib/array/uint32' ); + * + * var a = new Uint32Array( [ 0, 5 ] ); + * var b = new Uint32Array( [ 0, 10 ] ); + * + * var out = add.strided( a, 1, 0, b, 1, 0, new Uint32Array( 2 ), 1, 0 ); + * // returns [ 0, 15 ] + */ + strided, U extends NumericArray | Collection, V extends NumericArray | Collection>( a: T, sa: number, oa: number, b: U, sb: number, ob: number, out: V, so: number, oo: number ): V; +} + +/** +* Adds two unsigned 64-bit integers. +* +* @param a - unsigned 64-bit integer +* @param b - unsigned 64-bit integer +* @returns result +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var a = new Uint64( 5 ); +* var b = new Uint64( 10 ); +* +* var v = add( a, b ); +* // returns [ 15n ] +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = add.assign( 0, 5, 0, 10, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 0, 15 ] +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var a = new Uint32Array( [ 0, 5 ] ); +* var b = new Uint32Array( [ 0, 10 ] ); +* +* var out = add.strided( a, 1, 0, b, 1, 0, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 0, 15 ] +*/ +declare var add: Add; + + +// EXPORTS // + +export = add; diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/docs/types/test.ts b/lib/node_modules/@stdlib/number/uint64/base/add/docs/types/test.ts new file mode 100644 index 000000000000..1edb17f67f63 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/docs/types/test.ts @@ -0,0 +1,355 @@ +/* +* @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. +*/ + +import Uint64 = require( '@stdlib/number/uint64/ctor' ); +import add = require( './index' ); + + +// TESTS // + +// The function returns an unsigned 64-bit integer... +{ + const a = new Uint64( 5 ); + + add( a, a ); // $ExpectType Uint64 +} + +// The compiler throws an error if the function is provided a first argument which is not an unsigned 64-bit integer... +{ + const a = new Uint64( 5 ); + + add( true, a ); // $ExpectError + add( false, a ); // $ExpectError + add( null, a ); // $ExpectError + add( undefined, a ); // $ExpectError + add( '5', a ); // $ExpectError + add( [], a ); // $ExpectError + add( {}, a ); // $ExpectError + add( ( x: number ): number => x, a ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an unsigned 64-bit integer... +{ + const a = new Uint64( 5 ); + + add( a, true ); // $ExpectError + add( a, false ); // $ExpectError + add( a, null ); // $ExpectError + add( a, undefined ); // $ExpectError + add( a, '5' ); // $ExpectError + add( a, [] ); // $ExpectError + add( a, {} ); // $ExpectError + add( a, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const a = new Uint64( 5 ); + + add(); // $ExpectError + add( a ); // $ExpectError + add( a, a, a ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + add.assign( 1, 2, 3, 4, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array + add.assign( 1, 2, 3, 4, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + add.assign( 1, 2, 3, 4, [ 0, 0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + add.assign( true, 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( false, 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( null, 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( undefined, 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( '5', 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( [], 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( {}, 2, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( ( x: number ): number => x, 2, 3, 4, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + add.assign( 1, true, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, false, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, null, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, undefined, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, '5', 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, [], 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, {}, 3, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, ( x: number ): number => x, 3, 4, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + add.assign( 1, 2, true, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, false, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, null, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, undefined, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, '5', 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, [], 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, {}, 4, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, ( x: number ): number => x, 4, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + add.assign( 1, 2, 3, true, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, false, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, null, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, undefined, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, '5', out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, [], out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, {}, out, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a collection... +{ + add.assign( 1, 2, 3, 4, 1, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, true, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, false, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, null, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, undefined, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, '5', 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, [ '5' ], 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, {}, 1, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + add.assign( 1, 2, 3, 4, out, true, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, false, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, null, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, undefined, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, '5', 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, [], 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, {}, 0 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a seventh argument which is not a number... +{ + const out = new Uint32Array( 2 ); + + add.assign( 1, 2, 3, 4, out, 1, true ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, false ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, null ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, undefined ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, '5' ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, [] ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, {} ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const out = new Uint32Array( 2 ); + + add.assign(); // $ExpectError + add.assign( 1 ); // $ExpectError + add.assign( 1, 2 ); // $ExpectError + add.assign( 1, 2, 3 ); // $ExpectError + add.assign( 1, 2, 3, 4 ); // $ExpectError + add.assign( 1, 2, 3, 4, out ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1 ); // $ExpectError + add.assign( 1, 2, 3, 4, out, 1, 0, {} ); // $ExpectError +} + +// Attached to the main export is a `strided` method which returns a collection... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + + add.strided( a, 1, 0, b, 1, 0, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array + add.strided( a, 1, 0, b, 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + add.strided( a, 1, 0, b, 1, 0, [ 0, 0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `strided` method is provided a first argument which is not a collection... +{ + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( true, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( false, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( null, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( undefined, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( '5', 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( [ '5' ], 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( {}, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( ( x: number ): number => x, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a second argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, true, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, false, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, null, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, undefined, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, '5', 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, [], 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, {}, 0, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, ( x: number ): number => x, 0, b, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a third argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, 1, true, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, false, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, null, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, undefined, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, '5', b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, [], b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, {}, b, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, ( x: number ): number => x, b, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fourth argument which is not a collection... +{ + const a = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, 1, 0, true, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, false, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, null, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, undefined, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, '5', 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, [ '5' ], 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, {}, 1, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fifth argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, 1, 0, b, true, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, false, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, null, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, undefined, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, '5', 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, [], 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, {}, 0, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a sixth argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, 1, 0, b, 1, true, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, false, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, null, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, undefined, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, '5', out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, [], out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, {}, out, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a seventh argument which is not a collection... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + + add.strided( a, 1, 0, b, 1, 0, 1, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, true, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, false, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, null, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, undefined, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, '5', 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, [ '5' ], 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, {}, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an eighth argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, 1, 0, b, 1, 0, out, true, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, false, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, null, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, undefined, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, '5', 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, [], 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, {}, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a ninth argument which is not a number... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided( a, 1, 0, b, 1, 0, out, 1, true ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, false ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, null ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, undefined ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, '5' ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, [] ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, {} ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an unsupported number of arguments... +{ + const a = new Uint32Array( 2 ); + const b = new Uint32Array( 2 ); + const out = new Uint32Array( 2 ); + + add.strided(); // $ExpectError + add.strided( a ); // $ExpectError + add.strided( a, 1 ); // $ExpectError + add.strided( a, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b ); // $ExpectError + add.strided( a, 1, 0, b, 1 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1 ); // $ExpectError + add.strided( a, 1, 0, b, 1, 0, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/examples/index.js b/lib/node_modules/@stdlib/number/uint64/base/add/examples/index.js new file mode 100644 index 000000000000..68ea45358bba --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/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( '@stdlib/number/uint64/ctor' ); +var add = require( './../lib' ); + +var a = new Uint64( 5 ); +var b = new Uint64( 10 ); +var v = add( a, b ); +// returns [ 15n ] + +a = new Uint64( 1234567890 ); +b = new Uint64( 8765432109 ); +v = add( a, b ); // eslint-disable-line no-unused-vars +// returns [ 9999999999n ] diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/add/lib/assign.js new file mode 100644 index 000000000000..46317e85ef8b --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/lib/assign.js @@ -0,0 +1,58 @@ +/** +* @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'; + +// MAIN // + +/** +* Adds two unsigned 64-bit integers and assigns results to a provided output array. +* +* @param {uinteger} ah - high 32-bit word of the first unsigned 64-bit integer +* @param {uinteger} al - low 32-bit word of the first unsigned 64-bit integer +* @param {uinteger} bh - high 32-bit word of the second unsigned 64-bit integer +* @param {uinteger} bl - low 32-bit word of the second unsigned 64-bit integer +* @param {Collection} out - output array +* @param {integer} so - stride length +* @param {NonNegativeInteger} oo - starting index +* @returns {Collection} output array +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = assign( 0, 5, 0, 10, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 0, 15 ] +*/ +function assign( ah, al, bh, bl, out, so, oo ) { + var carry; + + ah >>>= 0; + al >>>= 0; + bh >>>= 0; + bl >>>= 0; + + out[ oo+so ] = ( al + bl ) >>> 0; // lo + carry = ( out[ oo+so ] < al ) >>> 0; + out[ oo ] = ( ah + bh + carry ) >>> 0; // hi + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/lib/index.js b/lib/node_modules/@stdlib/number/uint64/base/add/lib/index.js new file mode 100644 index 000000000000..02df860e5edb --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/lib/index.js @@ -0,0 +1,55 @@ +/** +* @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'; + +/** +* Add two unsigned 64-bit integers. +* +* @module @stdlib/number/uint64/base/add +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* var add = require( '@stdlib/number/uint64/base/add' ); +* +* var a = new Uint64( 5 ); +* var b = new Uint64( 10 ); +* +* var v = add( a, b ); +* // returns [ 15n ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); +var strided = require( './strided.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); +setReadOnly( main, 'strided', strided ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign", "strided": "main.strided" } diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/lib/main.js b/lib/node_modules/@stdlib/number/uint64/base/add/lib/main.js new file mode 100644 index 000000000000..18d3c27a12d0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/lib/main.js @@ -0,0 +1,59 @@ +/** +* @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 Uint64 = require( '@stdlib/number/uint64/ctor' ); +var assign = require( './assign.js' ); + + +// VARIABLES // + +var WORKSPACE = new Uint32Array( 2 ); + + +// MAIN // + +/** +* Adds two unsigned 64-bit integer. +* +* @param {Uint64} a - unsigned 64-bit integer +* @param {Uint64} b - unsigned 64-bit integer +* @returns {Uint64} result +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var a = new Uint64( 5 ); +* var b = new Uint64( 10 ); +* +* var v = add( a, b ); +* // returns [ 15n ] +*/ +function add( a, b ) { + assign( a.hi, a.lo, b.hi, b.lo, WORKSPACE, 1, 0 ); + return Uint64.from( WORKSPACE ); +} + + +// EXPORTS // + +module.exports = add; diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/lib/strided.js b/lib/node_modules/@stdlib/number/uint64/base/add/lib/strided.js new file mode 100644 index 000000000000..eb294c225e42 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/lib/strided.js @@ -0,0 +1,59 @@ +/** +* @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 assign = require( './assign.js' ); + + +// MAIN // + +/** +* Adds two unsigned 64-bit integers stored in integer-valued strided array views and assigns results to a provided strided output array. +* +* @param {Uint32Array} a - first unsigned 64-bit integer strided array view +* @param {integer} sa - stride length for `a` +* @param {NonNegativeInteger} oa - starting index for `a` +* @param {Uint32Array} b - second unsigned 64-bit integer strided array view +* @param {integer} sb - stride length for `b` +* @param {NonNegativeInteger} ob - starting index for `b` +* @param {Collection} out - output array +* @param {integer} so - stride length for `out` +* @param {NonNegativeInteger} oo - starting index for `out` +* @returns {Collection} output array +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var a = new Uint32Array( [ 0, 5 ] ); +* var b = new Uint32Array( [ 0, 10 ] ); +* +* var out = strided( a, 1, 0, b, 1, 0, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 0, 15 ] +*/ +function strided( a, sa, oa, b, sb, ob, out, so, oo ) { + assign( a[ oa ], a[ oa+sa ], b[ ob ], b[ ob+sb ], out, so, oo ); + return out; +} + + +// EXPORTS // + +module.exports = strided; diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/package.json b/lib/node_modules/@stdlib/number/uint64/base/add/package.json new file mode 100644 index 000000000000..83210c063c14 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/number/uint64/base/add", + "version": "0.0.0", + "description": "Add two unsigned 64-bit integers.", + "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", + "stdmath", + "mathematics", + "math", + "add", + "add64", + "addition", + "sum", + "arithmetic", + "unsigned", + "uint64", + "integer" + ] +} diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/test/test.assign.js b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.assign.js new file mode 100644 index 000000000000..73eb24356062 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.assign.js @@ -0,0 +1,86 @@ +/** +* @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 isEqualUint32Array = require( '@stdlib/assert/is-equal-uint32array' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var add = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof add, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds two unsigned 64-bit integers', function test( t ) { + var expected; + var out; + var v; + + // Trivial stride and offset + out = new Uint32Array( 2 ); + v = add( 1, 2, 3, 4, out, 1, 0 ); + expected = new Uint32Array( [ 4, 6 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Positive stride + out = new Uint32Array( 4 ); + v = add( 1, 2, 3, 4, out, 2, 0 ); + expected = new Uint32Array( [ 4, 0, 6, 0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Positive stride and non-zero offset + out = new Uint32Array( 4 ); + v = add( 1, 2, 3, 4, out, 2, 1 ); + expected = new Uint32Array( [ 0, 4, 0, 6 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Negative stride and non-zero offset + out = new Uint32Array( 2 ); + v = add( 1, 2, 3, 4, out, -1, 1 ); + expected = new Uint32Array( [ 6, 4 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // 64-bit overflow + out = new Uint32Array( 2 ); + v = add( UINT32_MAX, UINT32_MAX, 0, 1, out, 1, 0 ); + expected = new Uint32Array( [ 0, 0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // 32-bit carry-over + out = new Uint32Array( 2 ); + v = add( 0, UINT32_MAX, 0, 1, out, 1, 0 ); + expected = new Uint32Array( [ 1, 0 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/test/test.js b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.js new file mode 100644 index 000000000000..a85043445cf5 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.js @@ -0,0 +1,46 @@ +/** +* @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 isMethod = require( '@stdlib/assert/is-method' ); +var add = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof add, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( isMethod( add, 'assign' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( isMethod( add, 'strided' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/test/test.main.js b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.main.js new file mode 100644 index 000000000000..d5654cc3685d --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.main.js @@ -0,0 +1,116 @@ +/** +* @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 BigInt = require( '@stdlib/bigint/ctor' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var add = require( './../lib' ); + + +// VARIABLES // + +var HAS_BIGINT = hasBigIntSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof add, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds two unsigned 64-bit integers', function test( t ) { + var expected; + var out; + var a; + var b; + + // Small value + a = new Uint64( 5 ); + b = new Uint64( 10 ); + out = add( a, b ); + expected = new Uint64( 15 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + // Large value (sum more than 32-bit) + a = new Uint64( UINT32_MAX ); + b = new Uint64( 1 ); + out = add( a, b ); + expected = new Uint64( UINT32_MAX+1 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + // Large value (64-bit max sum) + a = new Uint64( UINT32_MAX ); + b = Uint64.of( UINT32_MAX, 0 ); + out = add( a, b ); + expected = Uint64.of( UINT32_MAX, UINT32_MAX ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + // 64-bit overflow + a = new Uint64( 1 ); + b = Uint64.of( UINT32_MAX, UINT32_MAX ); + out = add( a, b ); + expected = Uint64.of( 0, 0 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function adds two unsigned 64-bit integers (Randomized)', function test( t ) { + var expected; + var big64sum; + var values; + var out; + var a; + var b; + var x; + var i; + + if ( !HAS_BIGINT ) { + t.end(); + return; + } + + x = discreteUniform( 100, 0, UINT32_MAX, { + 'dtype': 'uint32' + }); + values = []; + for ( i = 0; i < x.length; i++ ) { + values.push( Uint64.of( x[i], x[(i+1)%x.length] ) ); + } + + for ( i = 0; i < values.length; i++ ) { + a = values[i]; + b = values[(i+1)%values.length]; + out = add( a, b ); + big64sum = BigInt.asUintN( 64, a.valueOf() + b.valueOf() ); + expected = new Uint64( big64sum ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + } + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/add/test/test.strided.js b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.strided.js new file mode 100644 index 000000000000..342793379066 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/add/test/test.strided.js @@ -0,0 +1,81 @@ +/** +* @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 isEqualUint32Array = require( '@stdlib/assert/is-equal-uint32array' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var add = require( './../lib/strided.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof add, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds two unsigned 64-bit integers', function test( t ) { + var expected; + var out; + var a; + var b; + var v; + + // Trivial stride and offset + a = new Uint32Array( [ 1, 2 ] ); + b = new Uint32Array( [ 3, 4 ] ); + out = new Uint32Array( 2 ); + v = add( a, 1, 0, b, 1, 0, out, 1, 0 ); + expected = new Uint32Array( [ 4, 6 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Positive stride + a = new Uint32Array( [ 1, 0, 0, 2, 0, 0 ] ); + b = new Uint32Array( [ 3, 0, 4, 0 ] ); + out = new Uint32Array( 2 ); + v = add( a, 3, 0, b, 2, 0, out, 1, 0 ); + expected = new Uint32Array( [ 4, 6 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Positive stride and non-zero offset + a = new Uint32Array( [ 0, 0, 1, 0, 0, 2 ] ); + b = new Uint32Array( [ 0, 3, 0, 4 ] ); + out = new Uint32Array( 2 ); + v = add( a, 3, 2, b, 2, 1, out, 1, 0 ); + expected = new Uint32Array( [ 4, 6 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Negative stride and non-zero offset + a = new Uint32Array( [ 0, 0, 2, 0, 0, 1 ] ); + b = new Uint32Array( [ 0, 4, 0, 3 ] ); + out = new Uint32Array( 2 ); + v = add( a, -3, 5, b, -2, 3, out, 1, 0 ); + expected = new Uint32Array( [ 4, 6 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + t.end(); +});