From d2a70014ecf1f1dd7d4200038b1987d1dcd36be1 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Thu, 29 Oct 2026 04:59:09 +0600 Subject: [PATCH 1/4] feat: add `number/int64/base/add` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/number/int64/base/add/README.md | 183 ++++++++++++++++++ .../int64/base/add/benchmark/benchmark.js | 130 +++++++++++++ .../number/int64/base/add/docs/repl.txt | 117 +++++++++++ .../int64/base/add/docs/types/index.d.ts | 130 +++++++++++++ .../number/int64/base/add/docs/types/test.ts | 87 +++++++++ .../number/int64/base/add/examples/index.js | 48 +++++ .../number/int64/base/add/lib/assign.js | 58 ++++++ .../number/int64/base/add/lib/index.js | 55 ++++++ .../@stdlib/number/int64/base/add/lib/main.js | 62 ++++++ .../number/int64/base/add/lib/strided.js | 59 ++++++ .../number/int64/base/add/package.json | 70 +++++++ .../number/int64/base/add/test/test.assign.js | 64 ++++++ .../number/int64/base/add/test/test.js | 44 +++++ .../number/int64/base/add/test/test.main.js | 119 ++++++++++++ .../int64/base/add/test/test.strided.js | 72 +++++++ 15 files changed, 1298 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/README.md create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/examples/index.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/lib/assign.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/lib/index.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/lib/main.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/lib/strided.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/package.json create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/test/test.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js create mode 100644 lib/node_modules/@stdlib/number/int64/base/add/test/test.strided.js diff --git a/lib/node_modules/@stdlib/number/int64/base/add/README.md b/lib/node_modules/@stdlib/number/int64/base/add/README.md new file mode 100644 index 000000000000..534bc221ed67 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/README.md @@ -0,0 +1,183 @@ + + +# add + +> Add two 64-bit signed integers. + +
+ +
+ + + +
+ +## Usage + +```javascript +var add = require( '@stdlib/number/int64/base/add' ); +``` + +#### add( a, b ) + +Adds two 64-bit signed integers. + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); + +var a = new Int64( 5 ); +var b = new Int64( 10 ); + +var v = add( a, b ); +// returns +``` + +#### add.assign( ah, al, bh, bl, out, stride, offset ) + +Adds two 64-bit signed 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( 1, 2, 3, 4, out, 1, 0 ); +// returns [ 4, 6 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **ah**: high 32-bit word of the first 64-bit signed integer. +- **al**: low 32-bit word of the first 64-bit signed integer. +- **bh**: high 32-bit word of the second 64-bit signed integer. +- **bl**: low 32-bit word of the second 64-bit signed integer. +- **out**: output array. +- **stride**: stride length for `out`. +- **offset**: starting index for `out`. + +#### add.strided( a, sa, oa, b, sb, ob, out, so, oo ) + +Adds two 64-bit signed 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( [ 1, 2 ] ); +var b = new Uint32Array( [ 3, 4 ] ); +var out = new Uint32Array( 2 ); + +var v = add.strided( a, 1, 0, b, 1, 0, out, 1, 0 ); +// returns [ 4, 6 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **a**: first 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words. +- **sa**: stride length for `a`. +- **oa**: starting index for `a`. +- **b**: second 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words. +- **sb**: stride length for `b`. +- **ob**: starting index for `b`. +- **out**: output array. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + +
+ + + + + +
+ +## Notes + +- Unlike signed integer overflow in C, overflow behavior is well-defined and follows two's complement wraparound semantics. + +
+ + + +
+ +## Examples + + + +```javascript +var Int64 = require( '@stdlib/number/int64/ctor' ); +var add = require( '@stdlib/number/int64/base/add' ); + +// Addition beyond JavaScript's safe integer limit (10^18 > 2^53 - 1): +var a = new Int64( 1e18 ); +var b = new Int64( 1 ); +var v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '1000000000000000000 + 1 = 1000000000000000001' + +a = new Int64( -1e18 ); +b = new Int64( -1 ); +v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '-1000000000000000000 + -1 = -1000000000000000001' + +a = new Int64( 1e18 ); +b = new Int64( -1 ); +v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '1000000000000000000 + -1 = 999999999999999999' + +// Signed two's complement overflow wrap-around (INT64_MAX + 1 = INT64_MIN): +a = Int64.of( 0x7fffffff, 0xffffffff ); +b = new Int64( 1 ); +v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '9223372036854775807 + 1 = -9223372036854775808' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/int64/base/add/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/int64/base/add/benchmark/benchmark.js new file mode 100644 index 000000000000..43a2e1778795 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/benchmark/benchmark.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var Uint32Array = require( '@stdlib/array/uint32' ); +var bench = require( '@stdlib/bench' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var Int64 = require( '@stdlib/number/int64/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 N; + var x; + var y; + var z; + var i; + + N = 100; + x = discreteUniform( N, 0, UINT32_MAX, options ); + values = []; + for ( i = 0; i < N; i++ ) { + values.push( Int64.of( x[ i ], x[ (i+1)%N ] ) ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = values[ i%N ]; + z = values[ (i+1)%N ]; + out = add( y, z ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !( out instanceof Int64 ) ) { + b.fail( 'should return an Int64 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/int64/base/add/docs/repl.txt b/lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt new file mode 100644 index 000000000000..44fc38654104 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt @@ -0,0 +1,117 @@ + +{{alias}}( a, b ) + Adds two 64-bit signed integers. + + Parameters + ---------- + a: Int64 + 64-bit signed integer. + + b: Int64 + 64-bit signed integer. + + Returns + ------- + out: Int64 + Result. + + Examples + -------- + > var a = new {{alias:@stdlib/number/int64/ctor}}( 5 ) + + > var b = new {{alias:@stdlib/number/int64/ctor}}( 10 ) + + > var out = {{alias}}( a, b ) + + + +{{alias}}.assign( ah, al, bh, bl, out, stride, offset ) + Adds two 64-bit signed integers and assigns results to a provided output + array. + + Parameters + ---------- + ah: integer + High 32-bit word of the first 64-bit signed integer. + + al: integer + Low 32-bit word of the first 64-bit signed integer. + + bh: integer + High 32-bit word of the second 64-bit signed integer. + + bl: integer + Low 32-bit word of the second 64-bit signed integer. + + out: ArrayLikeObject + Output array. + + stride: integer + Stride length. + + offset: 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 64-bit signed integers stored in integer-valued strided array + views and assigns results to a provided strided output array. + + Parameters + ---------- + a: ArrayLikeObject + First 64-bit signed integer strided array view containing interleaved + 32-bit unsigned integer high and low order words. + + sa: integer + Stride length for `a`. + + oa: integer + Starting index for `a`. + + b: ArrayLikeObject + Second 64-bit signed integer strided array view containing interleaved + 32-bit unsigned integer high and low order words. + + 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/int64/base/add/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/index.d.ts new file mode 100644 index 000000000000..14d99f18bd56 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/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 { Int64 } from '@stdlib/types/number'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for adding two 64-bit signed integers. +*/ +interface Add { + /** + * Adds two 64-bit signed integers. + * + * @param a - 64-bit signed integer + * @param b - 64-bit signed integer + * @returns result + * + * @example + * var Int64 = require( '@stdlib/number/int64/ctor' ); + * + * var a = new Int64( 5 ); + * var b = new Int64( 10 ); + * + * var v = add( a, b ); + * // returns + */ + ( a: Int64, b: Int64 ): Int64; + + /** + * Adds two 64-bit signed integers and assigns results to a provided output array. + * + * @param ah - high 32-bit word of the first 64-bit signed integer + * @param al - low 32-bit word of the first 64-bit signed integer + * @param bh - high 32-bit word of the second 64-bit signed integer + * @param bl - low 32-bit word of the second 64-bit signed integer + * @param out - output array + * @param stride - stride length + * @param offset - starting index + * @returns output array + * + * @example + * var Uint32Array = require( '@stdlib/array/uint32' ); + * + * var out = add.assign( 1, 2, 3, 4, new Uint32Array( 2 ), 1, 0 ); + * // returns [ 4, 6 ] + */ + assign>( ah: number, al: number, bh: number, bl: number, out: T, stride: number, offset: number ): T; + + /** + * Adds two 64-bit signed integers stored in integer-valued strided array views and assigns results to a provided strided output array. + * + * @param a - first 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words + * @param sa - stride length for `a` + * @param oa - starting index for `a` + * @param b - second 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words + * @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( [ 1, 2 ] ); + * var b = new Uint32Array( [ 3, 4 ] ); + * + * var out = add.strided( a, 1, 0, b, 1, 0, new Uint32Array( 2 ), 1, 0 ); + * // returns [ 4, 6 ] + */ + 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 64-bit signed integers. +* +* @param a - 64-bit signed integer +* @param b - 64-bit signed integer +* @returns result +* +* @example +* var Int64 = require( '@stdlib/number/int64/ctor' ); +* +* var a = new Int64( 5 ); +* var b = new Int64( 10 ); +* +* var v = add( a, b ); +* // returns +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = add.assign( 1, 2, 3, 4, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 4, 6 ] +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var a = new Uint32Array( [ 1, 2 ] ); +* var b = new Uint32Array( [ 3, 4 ] ); +* +* var out = add.strided( a, 1, 0, b, 1, 0, new Uint32Array( 2 ), 1, 0 ); +* // returns [ 4, 6 ] +*/ +declare var add: Add; + + +// EXPORTS // + +export = add; diff --git a/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts new file mode 100644 index 000000000000..aa0062727e16 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts @@ -0,0 +1,87 @@ +/* +* @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 Int64 = require( '@stdlib/number/int64/ctor' ); +import add = require( './index' ); + + +// TESTS // + +// The function returns a 64-bit signed integer... +{ + const a = new Int64( 5 ); + + add( a, a ); // $ExpectType Int64 +} + +// The compiler throws an error if the function is provided a first argument which is not a 64-bit signed integer... +{ + const a = new Int64( 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 a 64-bit signed integer... +{ + const a = new Int64( 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 Int64( 5 ); + + add(); // $ExpectError + add( a ); // $ExpectError + add( a, a, a ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns an array-like object containing numbers... +{ + const out = [ 0.0, 0.0 ]; + + add.assign( 1, 2, 3, 4, out, 1, 0 ); // $ExpectType number[] + add.assign( 1, 2, 3, 4, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + add.assign( 1, 2, 3, 4, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array +} + +// Attached to the main export is a `strided` method which returns an array-like object containing numbers... +{ + const a = [ 1.0, 2.0 ]; + const b = [ 3.0, 4.0 ]; + const out = [ 0.0, 0.0 ]; + + add.strided( a, 1, 0, b, 1, 0, out, 1, 0 ); // $ExpectType number[] + add.strided( new Float64Array( a ), 1, 0, new Float64Array( b ), 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + add.strided( new Uint32Array( a ), 1, 0, new Uint32Array( b ), 1, 0, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array +} diff --git a/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js b/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js new file mode 100644 index 000000000000..43cfa41289d2 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js @@ -0,0 +1,48 @@ +/** +* @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 Int64 = require( '@stdlib/number/int64/ctor' ); +var add = require( './../lib' ); + +// Addition beyond JavaScript's safe integer limit (10^18 > 2^53 - 1): +var a = new Int64( 1e18 ); +var b = new Int64( 1 ); +var v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '1000000000000000000 + 1 = 1000000000000000001' + +a = new Int64( -1e18 ); +b = new Int64( -1 ); +v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '-1000000000000000000 + -1 = -1000000000000000001' + +a = new Int64( 1e18 ); +b = new Int64( -1 ); +v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '1000000000000000000 + -1 = 999999999999999999' + +// Signed two's complement overflow wrap-around (INT64_MAX + 1 = INT64_MIN): +a = Int64.of( 0x7fffffff, 0xffffffff ); +b = new Int64( 1 ); +v = add( a, b ); +console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +// => '9223372036854775807 + 1 = -9223372036854775808' diff --git a/lib/node_modules/@stdlib/number/int64/base/add/lib/assign.js b/lib/node_modules/@stdlib/number/int64/base/add/lib/assign.js new file mode 100644 index 000000000000..d885531e40af --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/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 64-bit signed integers and assigns results to a provided output array. +* +* @param {uinteger} ah - high 32-bit word of the first 64-bit signed integer +* @param {uinteger} al - low 32-bit word of the first 64-bit signed integer +* @param {uinteger} bh - high 32-bit word of the second 64-bit signed integer +* @param {uinteger} bl - low 32-bit word of the second 64-bit signed 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/int64/base/add/lib/index.js b/lib/node_modules/@stdlib/number/int64/base/add/lib/index.js new file mode 100644 index 000000000000..05a9411248c1 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/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 64-bit signed integers. +* +* @module @stdlib/number/int64/base/add +* +* @example +* var Int64 = require( '@stdlib/number/int64/ctor' ); +* var add = require( '@stdlib/number/int64/base/add' ); +* +* var a = new Int64( 5 ); +* var b = new Int64( 10 ); +* +* var v = add( a, b ); +* // returns +*/ + +// 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/int64/base/add/lib/main.js b/lib/node_modules/@stdlib/number/int64/base/add/lib/main.js new file mode 100644 index 000000000000..aca15db20d01 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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 toWords = require( '@stdlib/number/int64/base/to-words' ).assign; +var words2int64 = require( '@stdlib/number/int64/ctor' ).of; +var assign = require( './assign.js' ); + + +// VARIABLES // + +var WORKSPACE = new Uint32Array( 6 ); + + +// MAIN // + +/** +* Adds two 64-bit signed integers. +* +* @param {Int64} a - 64-bit signed integer +* @param {Int64} b - 64-bit signed integer +* @returns {Int64} result +* +* @example +* var Int64 = require( '@stdlib/number/int64/ctor' ); +* +* var a = new Int64( 5 ); +* var b = new Int64( 10 ); +* +* var v = add( a, b ); +* // returns +*/ +function add( a, b ) { + toWords( a, WORKSPACE, 1, 0 ); + toWords( b, WORKSPACE, 1, 2 ); + assign( WORKSPACE[ 0 ], WORKSPACE[ 1 ], WORKSPACE[ 2 ], WORKSPACE[ 3 ], WORKSPACE, 1, 4 ); // eslint-disable-line max-len + return words2int64( WORKSPACE[ 4 ], WORKSPACE[ 5 ] ); +} + + +// EXPORTS // + +module.exports = add; diff --git a/lib/node_modules/@stdlib/number/int64/base/add/lib/strided.js b/lib/node_modules/@stdlib/number/int64/base/add/lib/strided.js new file mode 100644 index 000000000000..893475a0479f --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/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 64-bit signed integers stored in integer-valued strided array views and assigns results to a provided strided output array. +* +* @param {Collection} a - first 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words +* @param {integer} sa - stride length for `a` +* @param {NonNegativeInteger} oa - starting index for `a` +* @param {Collection} b - second 64-bit signed integer strided array view containing interleaved 32-bit unsigned integer high and low order words +* @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/int64/base/add/package.json b/lib/node_modules/@stdlib/number/int64/base/add/package.json new file mode 100644 index 000000000000..f124dc1bbe89 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/number/int64/base/add", + "version": "0.0.0", + "description": "Add two 64-bit signed 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", + "stdtypes", + "base", + "utilities", + "utility", + "utils", + "util", + "types", + "type", + "int64", + "signed", + "64-bit", + "integer", + "int", + "add", + "addition", + "sum" + ] +} diff --git a/lib/node_modules/@stdlib/number/int64/base/add/test/test.assign.js b/lib/node_modules/@stdlib/number/int64/base/add/test/test.assign.js new file mode 100644 index 000000000000..6b5e6419a29e --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/test/test.assign.js @@ -0,0 +1,64 @@ +/** +* @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/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 64-bit signed integers', function test( t ) { + var expected; + var out; + var v; + + // Trivial stride and offset: + out = new Uint32Array( 2 ); + v = add( 0, 5, 0, 10, out, 1, 0 ); + expected = new Uint32Array( [ 0, 15 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Positive stride: + out = new Uint32Array( 4 ); + v = add( 0, 5, 0, 10, out, 2, 0 ); + expected = new Uint32Array( [ 0, 0, 15, 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( 0, 5, 0, 10, out, 2, 1 ); + expected = new Uint32Array( [ 0, 0, 0, 15 ] ); + 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/int64/base/add/test/test.js b/lib/node_modules/@stdlib/number/int64/base/add/test/test.js new file mode 100644 index 000000000000..114810c2e415 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/test/test.js @@ -0,0 +1,44 @@ +/** +* @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.strictEqual( isMethod( add, 'assign' ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.strictEqual( isMethod( add, 'strided' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js b/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js new file mode 100644 index 000000000000..e074ce1569e4 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js @@ -0,0 +1,119 @@ +/** +* @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/int64/base/assert/is-equal' ); +var Int64 = require( '@stdlib/number/int64/ctor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var add = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !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 64-bit signed integers', function test( t ) { + var expected; + var out; + var a; + var b; + + // Small values: + a = new Int64( 5 ); + b = new Int64( 10 ); + out = add( a, b ); + expected = new Int64( 15 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + // Zero: + a = new Int64( 5 ); + b = new Int64( 0 ); + out = add( a, b ); + expected = new Int64( 5 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + // Negative values: + a = new Int64( -5 ); + b = new Int64( 5 ); + out = add( a, b ); + expected = new Int64( 0 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + a = new Int64( -10 ); + b = new Int64( -20 ); + out = add( a, b ); + expected = new Int64( -30 ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + + // Overflow wrapping (two's complement): + a = new Int64( BigInt( '9223372036854775807' ) ); // 2^63 - 1 + b = new Int64( 1 ); + out = add( a, b ); + expected = new Int64( BigInt( '-9223372036854775808' ) ); // -2^63 + t.ok( isEqual( out, expected ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function adds two 64-bit signed integers (random values)', opts, function test( t ) { + var big64sum; + var expected; + var values; + var out; + var a; + var b; + var x; + var i; + + x = discreteUniform( 100, 0, UINT32_MAX, { + 'dtype': 'uint32' + }); + values = []; + for ( i = 0; i < x.length; i++ ) { + values.push( Int64.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.asIntN( 64, a.valueOf() + b.valueOf() ); + expected = new Int64( big64sum ); + t.ok( isEqual( out, expected ), 'returns expected value' ); + } + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/int64/base/add/test/test.strided.js b/lib/node_modules/@stdlib/number/int64/base/add/test/test.strided.js new file mode 100644 index 000000000000..5d49f5be04f0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/int64/base/add/test/test.strided.js @@ -0,0 +1,72 @@ +/** +* @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 64-bit signed integers', function test( t ) { + var expected; + var out; + var a; + var b; + var v; + + // Trivial stride and offset: + a = new Uint32Array( [ 0, 5 ] ); + b = new Uint32Array( [ 0, 10 ] ); + out = new Uint32Array( 2 ); + v = add( a, 1, 0, b, 1, 0, out, 1, 0 ); + expected = new Uint32Array( [ 0, 15 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + // Positive stride: + a = new Uint32Array( [ 0, 0, 0, 5, 0, 0 ] ); + b = new Uint32Array( [ 0, 0, 10, 0 ] ); + out = new Uint32Array( 2 ); + v = add( a, 3, 0, b, 2, 0, out, 1, 0 ); + expected = new Uint32Array( [ 0, 15 ] ); + 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, 0, 0, 5, 0 ] ); + b = new Uint32Array( [ 0, 0, 0, 10 ] ); + out = new Uint32Array( 4 ); + v = add( a, 3, 1, b, 2, 1, out, 2, 1 ); + expected = new Uint32Array( [ 0, 0, 0, 15 ] ); + t.strictEqual( v, out, 'returns expected value' ); + t.ok( isEqualUint32Array( out, expected ), 'returns expected value' ); + + t.end(); +}); From adf6e0d1a57e3c45b94bc620f18eb4a54db799db Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Tue, 10 Nov 2026 22:57:47 +0600 Subject: [PATCH 2/4] docs: minor refactor in examples --- lib/node_modules/@stdlib/number/int64/base/add/README.md | 8 ++++---- .../@stdlib/number/int64/base/add/examples/index.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/number/int64/base/add/README.md b/lib/node_modules/@stdlib/number/int64/base/add/README.md index 534bc221ed67..4bc6fea83d32 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/README.md +++ b/lib/node_modules/@stdlib/number/int64/base/add/README.md @@ -135,26 +135,26 @@ var add = require( '@stdlib/number/int64/base/add' ); var a = new Int64( 1e18 ); var b = new Int64( 1 ); var v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '1000000000000000000 + 1 = 1000000000000000001' a = new Int64( -1e18 ); b = new Int64( -1 ); v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '-1000000000000000000 + -1 = -1000000000000000001' a = new Int64( 1e18 ); b = new Int64( -1 ); v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '1000000000000000000 + -1 = 999999999999999999' // Signed two's complement overflow wrap-around (INT64_MAX + 1 = INT64_MIN): a = Int64.of( 0x7fffffff, 0xffffffff ); b = new Int64( 1 ); v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '9223372036854775807 + 1 = -9223372036854775808' ``` diff --git a/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js b/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js index 43cfa41289d2..ebe4c3369af6 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js +++ b/lib/node_modules/@stdlib/number/int64/base/add/examples/index.js @@ -25,24 +25,24 @@ var add = require( './../lib' ); var a = new Int64( 1e18 ); var b = new Int64( 1 ); var v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '1000000000000000000 + 1 = 1000000000000000001' a = new Int64( -1e18 ); b = new Int64( -1 ); v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '-1000000000000000000 + -1 = -1000000000000000001' a = new Int64( 1e18 ); b = new Int64( -1 ); v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '1000000000000000000 + -1 = 999999999999999999' // Signed two's complement overflow wrap-around (INT64_MAX + 1 = INT64_MIN): a = Int64.of( 0x7fffffff, 0xffffffff ); b = new Int64( 1 ); v = add( a, b ); -console.log( '%s + %s = %s', a.toString(), b.toString(), v.toString() ); +console.log( '%s + %s = %s', a, b, v ); // => '9223372036854775807 + 1 = -9223372036854775808' From 1deeb28467b9f4f4008a24b570e9cb852b0bfde0 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Sat, 5 Dec 2026 03:09:42 +0600 Subject: [PATCH 3/4] chore: address review comments --- .../@stdlib/number/int64/base/add/README.md | 7 +- .../int64/base/add/docs/types/index.d.ts | 4 +- .../number/int64/base/add/docs/types/test.ts | 271 ++++++++++++++++++ .../number/int64/base/add/lib/index.js | 2 +- .../@stdlib/number/int64/base/add/lib/main.js | 2 +- .../number/int64/base/add/test/test.main.js | 16 ++ 6 files changed, 297 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/number/int64/base/add/README.md b/lib/node_modules/@stdlib/number/int64/base/add/README.md index 4bc6fea83d32..7f67487e7e7a 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/README.md +++ b/lib/node_modules/@stdlib/number/int64/base/add/README.md @@ -47,9 +47,14 @@ var a = new Int64( 5 ); var b = new Int64( 10 ); var v = add( a, b ); -// returns +// returns [ 15n ] ``` +The function supports the following parameters: + +- **a**: first 64-bit signed integer. +- **b**: second 64-bit signed integer. + #### add.assign( ah, al, bh, bl, out, stride, offset ) Adds two 64-bit signed integers and assigns results to a provided output array. diff --git a/lib/node_modules/@stdlib/number/int64/base/add/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/index.d.ts index 14d99f18bd56..881e47833d15 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/index.d.ts @@ -41,7 +41,7 @@ interface Add { * var b = new Int64( 10 ); * * var v = add( a, b ); - * // returns + * // returns [ 15n ] */ ( a: Int64, b: Int64 ): Int64; @@ -105,7 +105,7 @@ interface Add { * var b = new Int64( 10 ); * * var v = add( a, b ); -* // returns +* // returns [ 15n ] * * @example * var Uint32Array = require( '@stdlib/array/uint32' ); diff --git a/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts index aa0062727e16..f3a06e1a6efe 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts +++ b/lib/node_modules/@stdlib/number/int64/base/add/docs/types/test.ts @@ -75,6 +75,117 @@ import add = require( './index' ); add.assign( 1, 2, 3, 4, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array } +// 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 an array-like object containing numbers... { const a = [ 1.0, 2.0 ]; @@ -85,3 +196,163 @@ import add = require( './index' ); add.strided( new Float64Array( a ), 1, 0, new Float64Array( b ), 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array add.strided( new Uint32Array( a ), 1, 0, new Uint32Array( b ), 1, 0, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array } + +// 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/int64/base/add/lib/index.js b/lib/node_modules/@stdlib/number/int64/base/add/lib/index.js index 05a9411248c1..5fd74d7e52dc 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/lib/index.js +++ b/lib/node_modules/@stdlib/number/int64/base/add/lib/index.js @@ -31,7 +31,7 @@ * var b = new Int64( 10 ); * * var v = add( a, b ); -* // returns +* // returns [ 15n ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/number/int64/base/add/lib/main.js b/lib/node_modules/@stdlib/number/int64/base/add/lib/main.js index aca15db20d01..5894520f203d 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/lib/main.js +++ b/lib/node_modules/@stdlib/number/int64/base/add/lib/main.js @@ -47,7 +47,7 @@ var WORKSPACE = new Uint32Array( 6 ); * var b = new Int64( 10 ); * * var v = add( a, b ); -* // returns +* // returns [ 15n ] */ function add( a, b ) { toWords( a, WORKSPACE, 1, 0 ); diff --git a/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js b/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js index e074ce1569e4..c168b7194050 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js +++ b/lib/node_modules/@stdlib/number/int64/base/add/test/test.main.js @@ -78,6 +78,15 @@ tape( 'the function adds two 64-bit signed integers', function test( t ) { expected = new Int64( -30 ); t.ok( isEqual( out, expected ), 'returns expected value' ); + t.end(); +}); + +tape( 'the function adds two 64-bit signed integers (overflow/underflow)', opts, function test( t ) { + var expected; + var out; + var a; + var b; + // Overflow wrapping (two's complement): a = new Int64( BigInt( '9223372036854775807' ) ); // 2^63 - 1 b = new Int64( 1 ); @@ -85,6 +94,13 @@ tape( 'the function adds two 64-bit signed integers', function test( t ) { expected = new Int64( BigInt( '-9223372036854775808' ) ); // -2^63 t.ok( isEqual( out, expected ), 'returns expected value' ); + // Underflow wrapping (two's complement): + a = new Int64( BigInt( '-9223372036854775808' ) ); // -2^63 + b = new Int64( -1 ); + out = add( a, b ); + expected = new Int64( BigInt( '9223372036854775807' ) ); // 2^63 - 1 + t.ok( isEqual( out, expected ), 'returns expected value' ); + t.end(); }); From 4f751923782c2dcda0e7e3cd348511716ae3bf15 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Sat, 5 Dec 2026 03:18:45 +0600 Subject: [PATCH 4/4] docs: add value annotations to Int64 doctests in repl.txt --- .../@stdlib/number/int64/base/add/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt b/lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt index 44fc38654104..4cc816bff153 100644 --- a/lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt +++ b/lib/node_modules/@stdlib/number/int64/base/add/docs/repl.txt @@ -18,11 +18,11 @@ Examples -------- > var a = new {{alias:@stdlib/number/int64/ctor}}( 5 ) - + [ 5n ] > var b = new {{alias:@stdlib/number/int64/ctor}}( 10 ) - + [ 10n ] > var out = {{alias}}( a, b ) - + [ 15n ] {{alias}}.assign( ah, al, bh, bl, out, stride, offset )