From 5439fef21840f69d88241fce61fca0ad8ab67895 Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Tue, 7 Jul 2026 14:03:12 +0600 Subject: [PATCH 01/16] feat: add `number/uint64/base/string2words` --- 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 --- --- .../number/uint64/base/string2words/README.md | 136 ++++++++++ .../base/string2words/benchmark/benchmark.js | 118 +++++++++ .../uint64/base/string2words/docs/repl.txt | 69 ++++++ .../base/string2words/docs/types/index.d.ts | 113 +++++++++ .../base/string2words/docs/types/test.ts | 133 ++++++++++ .../base/string2words/examples/index.js | 37 +++ .../uint64/base/string2words/lib/assign.js | 204 +++++++++++++++ .../uint64/base/string2words/lib/index.js | 57 +++++ .../uint64/base/string2words/lib/main.js | 58 +++++ .../uint64/base/string2words/package.json | 73 ++++++ .../base/string2words/test/test.assign.js | 232 ++++++++++++++++++ .../uint64/base/string2words/test/test.js | 40 +++ .../base/string2words/test/test.main.js | 52 ++++ 13 files changed, 1322 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/README.md create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/examples/index.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/lib/index.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/package.json create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.js create mode 100644 lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md b/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md new file mode 100644 index 000000000000..917d7b3b2dea --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md @@ -0,0 +1,136 @@ + + +# string2words + +> Parse a string representation of a 64-bit unsigned integer into high and low 32-bit words. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var string2words = require( '@stdlib/number/uint64/base/string2words' ); +``` + +#### string2words( str, radix ) + +Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words. + +```javascript +var w = string2words( '1234', 10 ); +// returns [ 0, 1234 ] +``` + +The function returns an array containing two elements: a higher order word and a lower order word. The lower order word contains the less significant bits, while the higher order word contains the more significant bits. + +#### string2words.assign( str, radix, out, stride, offset ) + +Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words and assigns results to a provided output array. + +```javascript +var Uint32Array = require( '@stdlib/array/uint32' ); + +var out = new Uint32Array( 2 ); +// returns [ 0, 0 ] + +var w = string2words.assign( 'ffffffffffffffff', 16, out, 1, 0 ); +// returns [ 4294967295, 4294967295 ] + +var bool = ( w === out ); +// returns true +``` + +
+ + + + + +
+ +## Notes + +- The input string must be a valid representation of an unsigned 64-bit integer in the specified radix, containing no whitespace, sign symbols, or leading zeros. +- If the provided string represents a value greater than `2^64-1` or the radix is invalid then `0` is assigned to both high and low words. + +
+ + + + + +
+ +## Examples + +```javascript +var string2words = require( '@stdlib/number/uint64/base/string2words' ); + +var w = string2words( '1234', 10 ); +console.log( w ); +// => [ 0, 1234 ] + +w = string2words( 'abcd', 16 ); +console.log( w ); +// => [ 0, 43981 ] + +w = string2words( '18446744073709551615', 10 ); +console.log( w ); +// => [ 4294967295, 4294967295 ] + +w = string2words( '3w5e11264sgsf', 36 ); +console.log( w ); +// => [ 4294967295, 4294967295 ] +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/benchmark/benchmark.js new file mode 100644 index 000000000000..97c82db9e5c7 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/benchmark/benchmark.js @@ -0,0 +1,118 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var isArray = require( '@stdlib/assert/is-array' ); +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 string2words = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'uint32' +}; + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var radices; + var values; + var rad; + var N; + var a; + var i; + var w; + var x; + + N = 100; + x = discreteUniform( N, 0, UINT32_MAX, options ); + values = []; + radices = []; + for ( i = 0; i < N; i++ ) { + a = Uint64.of( x[ i ], x[ (i+1)%N ] ); + for ( rad = 2; rad <= 36; rad++ ) { + values.push( a.toString( rad ) ); + radices.push( rad ); + } + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + w = string2words( values[ i % N ], radices[ i % N ] ); + if ( typeof w !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( w ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:assign', pkg ), function benchmark( b ) { + var radices; + var values; + var out; + var rad; + var N; + var a; + var i; + var w; + var x; + + N = 100; + x = discreteUniform( N, 0, UINT32_MAX, options ); + values = []; + radices = []; + for ( i = 0; i < N; i++ ) { + a = Uint64.of( x[ i ], x[ (i+1)%N ] ); + for ( rad = 2; rad <= 36; rad++ ) { + values.push( a.toString( rad ) ); + radices.push( rad ); + } + } + + out = new Uint32Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + w = string2words.assign( values[ i % N ], radices[ i % N ], out, 1, 0 ); + if ( typeof w !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( w !== out ) { + b.fail( 'should return the output array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/repl.txt b/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/repl.txt new file mode 100644 index 000000000000..4710cc02d131 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/repl.txt @@ -0,0 +1,69 @@ + +{{alias}}( str, radix ) + Parses a string representation of a 64-bit unsigned integer into high and + low 32-bit words. + + The function returns an array with two elements: a higher order word and a + lower order word, respectively. The lower order word contains the less + significant bits, while the higher order word contains the more significant + bits. + + Parameters + ---------- + str: string + String representation of a 64-bit unsigned integer. + + radix: integer + Radix (base) to use for string conversion (2-36). + + Returns + ------- + out: Array + High and low words as 32-bit unsigned integers. + + Examples + -------- + > var w = {{alias}}( '1234', 10 ) + [ 0, 1234 ] + > w = {{alias}}( 'abcd', 16 ) + [ 0, 43981 ] + > w = {{alias}}( '3w5e11264sgsf', 36 ) + [ 4294967295, 4294967295 ] + + +{{alias}}.assign( str, radix, out, stride, offset ) + Parses a string representation of a 64-bit unsigned integer into high and + low 32-bit words and assigns results to a provided output array. + + Parameters + ---------- + str: string + String representation of a 64-bit unsigned integer. + + radix: integer + Radix (base) to use for string conversion (2-36). + + out: Array|TypedArray|Object + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array index offset. + + Returns + ------- + out: Array|TypedArray|Object + Output array. + + Examples + -------- + > var out = new {{alias:@stdlib/array/uint32}}( 2 ); + > var w = {{alias}}.assign( 'ffffffffffffffff', 16, out, 1, 0 ) + [ 4294967295, 4294967295 ] + > var bool = ( w === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/index.d.ts new file mode 100644 index 000000000000..dcd5aeb55102 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/index.d.ts @@ -0,0 +1,113 @@ +/* +* @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 { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface describing `string2words`. +*/ +interface StringToWords { + /** + * Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words. + * + * @param str - string representation of a 64-bit unsigned integer + * @param radix - radix (base) to use for string conversion (2-36) + * @returns output array + * + * @example + * var out = string2words( '1234', 10 ); + * // returns [ 0, 1234 ] + * + * out = string2words( '18446744073709551615', 10 ); + * // returns [ 4294967295, 4294967295 ] + * + * out = string2words( 'ffffffffffffffff', 16 ); + * // returns [ 4294967295, 4294967295 ] + * + * out = string2words( '3w5e11264sgsf', 36 ); + * // returns [ 4294967295, 4294967295 ] + */ + ( str: string, radix: number ): [ number, number ]; + + /** + * Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words and assigns results to a provided output array. + * + * @param str - string representation of a 64-bit unsigned integer + * @param radix - radix (base) to use for string conversion (2-36) + * @param out - output array + * @param stride - stride length + * @param offset - starting index + * @returns output array + * + * @example + * var Uint32Array = require( '@stdlib/array/uint32' ); + * + * var out = new Uint32Array( 2 ); + * // returns [ 0, 0 ] + * + * var w = string2words.assign( 'ffffffffffffffff', 16, out, 1, 0 ); + * // returns [ 4294967295, 4294967295 ] + * + * var bool = ( w === out ); + * // returns true + */ + assign>( str: string, radix: number, out: T, stride: number, offset: number ): T; +} + +/** +* Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words. +* +* @param str - string representation of a 64-bit unsigned integer +* @param radix - radix (base) to use for string conversion (2-36) +* @returns output array +* +* @example +* var out = string2words( '1234', 10 ); +* // returns [ 0, 1234 ] +* +* out = string2words( '18446744073709551615', 10 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = string2words( 'ffffffffffffffff', 16 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = string2words( '3w5e11264sgsf', 36 ); +* // returns [ 4294967295, 4294967295 ] +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = new Uint32Array( 2 ); +* // returns [ 0, 0 ] +* +* var w = string2words.assign( 'ffffffffffffffff', 16, out, 1, 0 ); +* // returns [ 4294967295, 4294967295 ] +* +* var bool = ( w === out ); +* // returns true +*/ +declare var string2words: StringToWords; + + +// EXPORTS // + +export = string2words; diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/test.ts b/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/test.ts new file mode 100644 index 000000000000..08a1420095c4 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/docs/types/test.ts @@ -0,0 +1,133 @@ +/* +* @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 string2words = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + string2words( '1234', 10 ); // $ExpectType [number, number] +} + +// The compiler throws an error if the function is provided a first argument that is not a string... +{ + string2words( 5, 10 ); // $ExpectError + string2words( true, 10 ); // $ExpectError + string2words( false, 10 ); // $ExpectError + string2words( null, 10 ); // $ExpectError + string2words( {}, 10 ); // $ExpectError + string2words( ( x: number ): number => x, 10 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + string2words( '1234', '5' ); // $ExpectError + string2words( '1234', true ); // $ExpectError + string2words( '1234', false ); // $ExpectError + string2words( '1234', null ); // $ExpectError + string2words( '1234', {} ); // $ExpectError + string2words( '1234', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + string2words(); // $ExpectError + string2words( '1234', 10, 1 ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns an array-like object containing numbers... +{ + string2words.assign( '1234', 10, [ 0, 0 ], 1, 0 ); // $ExpectType number[] + string2words.assign( '1234', 10, new Uint32Array( 2 ), 1, 0 ); // $ExpectType Uint32Array + string2words.assign( '1234', 10, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a string... +{ + const out = [ 0.0, 0.0 ]; + + string2words.assign( 5, 10, out, 1, 0 ); // $ExpectError + string2words.assign( true, 10, out, 1, 0 ); // $ExpectError + string2words.assign( false, 10, out, 1, 0 ); // $ExpectError + string2words.assign( null, 10, out, 1, 0 ); // $ExpectError + string2words.assign( [], 10, out, 1, 0 ); // $ExpectError + string2words.assign( {}, 10, out, 1, 0 ); // $ExpectError + string2words.assign( ( x: number ): number => x, 10, 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 = [ 0.0, 0.0 ]; + + string2words.assign( '1234', '5', out, 1, 0 ); // $ExpectError + string2words.assign( '1234', true, out, 1, 0 ); // $ExpectError + string2words.assign( '1234', false, out, 1, 0 ); // $ExpectError + string2words.assign( '1234', null, out, 1, 0 ); // $ExpectError + string2words.assign( '1234', [], out, 1, 0 ); // $ExpectError + string2words.assign( '1234', {}, out, 1, 0 ); // $ExpectError + string2words.assign( '1234', ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an array-like object... +{ + string2words.assign( '1234', 10, 1, 1, 0 ); // $ExpectError + string2words.assign( '1234', 10, true, 1, 0 ); // $ExpectError + string2words.assign( '1234', 10, false, 1, 0 ); // $ExpectError + string2words.assign( '1234', 10, null, 1, 0 ); // $ExpectError + string2words.assign( '1234', 10, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const out = [ 0.0, 0.0 ]; + + string2words.assign( '1234', 10, out, '5', 0 ); // $ExpectError + string2words.assign( '1234', 10, out, true, 0 ); // $ExpectError + string2words.assign( '1234', 10, out, false, 0 ); // $ExpectError + string2words.assign( '1234', 10, out, null, 0 ); // $ExpectError + string2words.assign( '1234', 10, out, [], 0 ); // $ExpectError + string2words.assign( '1234', 10, out, {}, 0 ); // $ExpectError + string2words.assign( '1234', 10, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const out = [ 0.0, 0.0 ]; + + string2words.assign( '1234', 10, out, 1, '5' ); // $ExpectError + string2words.assign( '1234', 10, out, 1, true ); // $ExpectError + string2words.assign( '1234', 10, out, 1, false ); // $ExpectError + string2words.assign( '1234', 10, out, 1, null ); // $ExpectError + string2words.assign( '1234', 10, out, 1, [] ); // $ExpectError + string2words.assign( '1234', 10, out, 1, {} ); // $ExpectError + string2words.assign( '1234', 10, 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 = [ 0.0, 0.0 ]; + + string2words.assign(); // $ExpectError + string2words.assign( '1234' ); // $ExpectError + string2words.assign( '1234', 10 ); // $ExpectError + string2words.assign( '1234', 10, out ); // $ExpectError + string2words.assign( '1234', 10, out, 1 ); // $ExpectError + string2words.assign( '1234', 10, out, 1, 0, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/examples/index.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/examples/index.js new file mode 100644 index 000000000000..d9eda984a20e --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 string2words = require( './../lib' ); + +var w = string2words( '1234', 10 ); +console.log( w ); +// => [ 0, 1234 ] + +w = string2words( 'abcd', 16 ); +console.log( w ); +// => [ 0, 43981 ] + +w = string2words( '18446744073709551615', 10 ); +console.log( w ); +// => [ 4294967295, 4294967295 ] + +w = string2words( '3w5e11264sgsf', 36 ); +console.log( w ); +// => [ 4294967295, 4294967295 ] diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js new file mode 100644 index 000000000000..18d7b1f09a2f --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -0,0 +1,204 @@ +/** +* @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'; + +// VARIABLES // + +var TWO_32 = 0x100000000; // 2^32 + +/* eslint-disable array-element-newline */ + +/** +* A flat, strided array containing metadata for parsing large numeric strings into 64-bit values within JavaScript's 53-bit safe integer precision limits. +* +* Each radix from 2 to 36 is represented by a 3-element tuple: `[chunk1_len, chunk2_len, multiplier]` +* +* ## Tuple Properties +* +* - **chunk1_len**: The maximum number of digits that can be safely parsed in a single pass without exceeding `Number.MAX_SAFE_INTEGER`. +* - **chunk2_len**: The remaining number of digits required to fulfill the maximum width of a 64-bit unsigned integer for that radix. +* - **multiplier**: The positional weight scalar ($radix^{chunk2\_len}$) used to shift the place value of the first chunk when aggregating the final 64-bit split. +*/ +var CHUNKMAP = [ + // , , // radix + 53, 11, 2048, // 2 + 33, 8, 6561, // 3 + 26, 6, 4096, // 4 + 22, 6, 15625, // 5 + 20, 5, 7776, // 6 + 18, 5, 16807, // 7 + 17, 5, 32768, // 8 + 16, 5, 59049, // 9 + 15, 5, 100000, // 10 + 15, 4, 14641, // 11 + 14, 4, 20736, // 12 + 14, 4, 28561, // 13 + 13, 4, 38416, // 14 + 13, 4, 50625, // 15 + 13, 3, 4096, // 16 + 12, 4, 83521, // 17 + 12, 4, 104976, // 18 + 12, 4, 130321, // 19 + 12, 3, 8000, // 20 + 12, 3, 9261, // 21 + 11, 4, 234256, // 22 + 11, 4, 279841, // 23 + 11, 3, 13824, // 24 + 11, 3, 15625, // 25 + 11, 3, 17576, // 26 + 11, 3, 19683, // 27 + 11, 3, 21952, // 28 + 10, 4, 707281, // 29 + 10, 4, 810000, // 30 + 10, 3, 29791, // 31 + 10, 3, 32768, // 32 + 10, 3, 35937, // 33 + 10, 3, 39304, // 34 + 10, 3, 42875, // 35 + 10, 3, 46656 // 36 +]; + +/* eslint-enable array-element-newline */ + +/** +* Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words using two-step chunking.. +* +* @private +* @param {string} str - string representation of a 64-bit unsigned integer +* @param {PositiveInteger} radix - radix (base) to use for string conversion (2-36) +* @param {PositiveInteger} len1 - length of the first chunk +* @param {PositiveInteger} len2 - length of the second chunk +* @param {PositiveInteger} mult - multiplier for the place value calculation (radix raised to the power of len2) +* @param {Collection} out - output array +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - starting index +* @returns {Collection} output array +* +* @example +* var out = chunkedParse( '1111111111111111111111111111111111111111111111111111111111111111', 2, CHUNKMAP[0], CHUNKMAP[1], CHUNKMAP[2], [ 0, 0 ], 1, 0 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = chunkedParse( '18446744073709551615', 10, CHUNKMAP[24], CHUNKMAP[25], CHUNKMAP[26], [ 0, 0 ], 1, 0 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = chunkedParse( '3w5e11264sgsf', 36, CHUNKMAP[102], CHUNKMAP[103], CHUNKMAP[104], [ 0, 0 ], 1, 0 ); +* // returns [ 4294967295, 4294967295 ] +*/ +function chunkedParse( str, radix, len1, len2, mult, out, stride, offset ) { + var chunk1; + var chunk2; + var hi; + var lo; + + if ( str.length <= len1 ) { + // Parse in a single pass when input length is within chunk1 length + chunk1 = parseInt( str, radix ); + } else { + // Otherwise use a big chunk1 (start-aligned) and a small chunk2 (end-aligned) + chunk1 = parseInt( str.slice( 0, -len2 ), radix ); // Everything until last `len2` digits + chunk2 = parseInt( str.slice( -len2 ), radix ); // `len2` digits from the end + } + + hi = ( chunk1 / TWO_32 ) >>> 0; // Integer division by 2^32 + lo = chunk1 >>> 0; // 32-bit truncation + + // Process chunk2 if applicable + if ( str.length > len1 ) { + lo = ( lo * mult ) + chunk2; + hi = ( hi * mult ) + ( ( lo / TWO_32 ) >>> 0 ); + lo >>>= 0; // 32-bit truncation + + // Check if too big for uint64 + if ( hi >= TWO_32 ) { + hi = lo = 0; + } + } + + out[ offset ] = hi; + out[ offset + stride ] = lo; + return out; +} + + +// MAIN // + +/** +* Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words and assigns results to a provided output array. +* +* @param {string} str - string representation of a 64-bit unsigned integer +* @param {PositiveInteger} radix - radix (base) to use for string conversion (2-36) +* @param {Collection} out - output array +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - starting index +* @returns {Collection} output array +* +* @example +* var Uint32Array = require( '@stdlib/array/uint32' ); +* +* var out = new Uint32Array( 2 ); +* // returns [ 0, 0 ] +* +* var w = assign( 'ffffffffffffffff', 16, out, 1, 0 ); +* // returns [ 4294967295, 4294967295 ] +* +* var bool = ( w === out ); +* // returns true +*/ +function assign( str, radix, out, stride, offset ) { + var len1; + var len2; + var mult; + var idx; + + // Invalid radix + if ( !( radix >= 2 && radix <= 36 ) ) { + out[ offset ] = out[ offset + stride ] = 0; + return out; + } + + // Compute the index into a pre-computed strided table: + idx = 3 * ( radix-2 ); + + // Use a pre-computed table to select chunk lengths and the multiplier: + len1 = CHUNKMAP[ idx ]; + len2 = CHUNKMAP[ idx+1 ]; + mult = CHUNKMAP[ idx+2 ]; + + // Check if too big for uint64: + if ( str.length > len1+len2 ) { + out[ offset ] = out[ offset + stride ] = 0; + return out; + } + + // Fast path for bases 2, 4, and 16, thanks to evenly splittable 32-bit halves + if ( radix === 2 || radix === 4 || radix === 16 ) { + len1 = ( len1 + len2 ) / 2; + out[ offset ] = parseInt( '0' + str.slice( 0, -len1 ), radix ); // Adding leading zero in case the higher slice is empty + out[ offset + stride ] = parseInt( str.slice( -len1 ), radix ); + return out; + } + + // General path for other bases + return chunkedParse( str, radix, len1, len2, mult, out, stride, offset ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/index.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/index.js new file mode 100644 index 000000000000..73cf1087db5c --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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'; + +/** +* Parse a string representation of a 64-bit unsigned integer into high and low 32-bit words. +* +* @module @stdlib/number/uint64/base/string2words +* +* @example +* var string2words = require( '@stdlib/number/uint64/base/string2words' ); +* +* var out = string2words( '1234', 10 ); +* // returns [ 0, 1234 ] +* +* out = string2words( '18446744073709551615', 10 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = string2words( 'ffffffffffffffff', 16 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = string2words( '3w5e11264sgsf', 36 ); +* // returns [ 4294967295, 4294967295 ] +*/ + + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var assign = require( './assign.js' ); +var main = require( './main.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js new file mode 100644 index 000000000000..c607682499a9 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.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'; + +// MODULES // + +var assign = require( './assign.js' ); + + +// MAIN // + + +// MAIN // + +/** +* Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words. +* +* @param {string} str - string representation of a 64-bit unsigned integer +* @param {PositiveInteger} radix - radix (base) to use for string conversion (2-36) +* @returns {Collection} output array +* +* @example +* var out = string2words( '1234', 10 ); +* // returns [ 0, 1234 ] +* +* out = string2words( '18446744073709551615', 10 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = string2words( 'ffffffffffffffff', 16 ); +* // returns [ 4294967295, 4294967295 ] +* +* out = string2words( '3w5e11264sgsf', 36 ); +* // returns [ 4294967295, 4294967295 ] +*/ +function string2words( str, radix ) { + return assign( str, radix, [ 0, 0 ], 1, 0 ); +} + + +// EXPORTS // + +module.exports = string2words; diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/package.json b/lib/node_modules/@stdlib/number/uint64/base/string2words/package.json new file mode 100644 index 000000000000..67879c33dfe6 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/number/uint64/base/string2words", + "version": "0.0.0", + "description": "Parse a string representation of a 64-bit unsigned integer into high and low 32-bit words.", + "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", + "uint64", + "unsigned", + "64-bit", + "integer", + "int", + "string", + "parse", + "words", + "split", + "high", + "low" + ] +} diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js new file mode 100644 index 000000000000..20091e66f539 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js @@ -0,0 +1,232 @@ +/** +* @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 Uint32Array = require( '@stdlib/array/uint32' ); +var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); +var isEqualArray = require( '@stdlib/assert/is-equal-array' ); +var isInteger = require( '@stdlib/assert/is-integer' ); +var BigInt = require( '@stdlib/bigint/ctor' ); +var toWords = require( '@stdlib/number/uint64/base/to-words' ); +var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); +var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var string2words = require( './../lib/assign.js' ); + + +// VARIABLES // + +var HAS_BIGINT = hasBigIntSupport(); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof string2words, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a two-element numeric array containing integers', function test( t ) { + var out; + var w; + + out = [ 0, 0 ]; + w = string2words( '1234', 10, out, 1, 0 ); + + t.strictEqual( w, out, 'returns expected value' ); + t.strictEqual( isInteger( w[0] ), true, 'returns expected value' ); + t.strictEqual( isInteger( w[1] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function parses a string representation of a 64-bit unsigned integer into high and low 32-bit words', function test( t ) { + var out; + var w; + + out = [ 0, 0 ]; + w = string2words( '18446744073709551615', 10, out, 1, 0 ); + + t.strictEqual( w, out, 'returns expected value' ); + t.strictEqual( w[0], 4294967295, 'returns expected value' ); + t.strictEqual( w[1], 4294967295, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function parses a string representation of a 64-bit unsigned integer into high and low 32-bit words in bases 2 through 36', function test( t ) { + var expected; + var values; + var out; + var rad; + var i; + var s; + var w; + + values = [ + 0, + 1, + 2, + 3, + 4, + 5, + 10, + 99, + 100, + 999, + 1000, + 999999, + 1000000, + 999999999, + 1000000000, + UINT32_MAX, + UINT32_MAX + 1, + 9007199254740881, // Largest prime under 2^53 + MAX_SAFE_INTEGER - 1, + MAX_SAFE_INTEGER + ]; + + out = [ 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + values[ i ] = new Uint64( values[ i ] ); // Convert to Uint64 + expected = toWords( values[ i ] ); // Extract words from Uint64 for verification + + for ( rad = 2; rad <= 36; rad++ ) { + s = values[ i ].toString( rad ); // Convert the Uint64 to string with a radix + w = string2words( s, rad, out, 1, 0 ); // Extract words from the string reperesentation + + t.ok( isEqualArray( w, expected ), 'returns expected value' ); + t.strictEqual( w, out, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the function parses a string representation of a 64-bit unsigned integer into high and low 32-bit words in bases 2 through 36 (larger than max safe integer)', function test( t ) { + var expected; + var values; + var out; + var rad; + var i; + var s; + var w; + + if ( !HAS_BIGINT ) { + t.end(); + return; + } + + values = [ + '9007199254740992', // MAX_SAFE_INTEGER + 1 + '9999999999999999', + '10000000000000000', + '99999999999999999', + '100000000000000000', + '999999999999999999', + '1000000000000000000', + '9223372036854775783', // Largest prime under 2^63 + '9999999999999999999', + '10000000000000000000', + '18446744073709551557', // Largest prime under 2^64 + '18446744073709551615' // 2^64 - 1 + ]; + + out = [ 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + values[ i ] = new Uint64( BigInt( values[ i ] ) ); // Convert to Uint64 + expected = toWords( values[ i ] ); // Extract words from Uint64 for verification + + for ( rad = 2; rad <= 36; rad++ ) { + s = values[ i ].toString( rad ); // Convert Uint64 to string with a radix + w = string2words( s, rad, out, 1, 0 ); // Extract words from the string reperesentation + + t.ok( isEqualArray( w, expected ), 'returns expected value' ); + t.strictEqual( w, out, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the function supports providing an output object (array)', function test( t ) { + var out; + var w; + + out = [ 0, 0 ]; + w = string2words( '4294967296', 10, out, 1, 0 ); + + t.strictEqual( w, out, 'returns expected value' ); + t.strictEqual( w[ 0 ], 1, 'returns expected value' ); + t.strictEqual( w[ 1 ], 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an output object (typed array)', function test( t ) { + var out; + var w; + + out = new Uint32Array( 2 ); + w = string2words( '4294967296', 10, out, 1, 0 ); + + t.strictEqual( w, out, 'returns expected value' ); + t.strictEqual( w[ 0 ], 1, 'returns expected value' ); + t.strictEqual( w[ 1 ], 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var out; + var val; + + out = new Uint32Array( 4 ); + val = string2words( '4294967298', 10, out, 2, 0 ); + + t.strictEqual( val, out, 'returns expected value' ); + t.strictEqual( val[ 0 ], 1, 'returns expected value' ); + t.strictEqual( val[ 1 ], 0, 'returns expected value' ); + t.strictEqual( val[ 2 ], 2, 'returns expected value' ); + t.strictEqual( val[ 3 ], 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying an offset', function test( t ) { + var out; + var val; + + out = new Uint32Array( 4 ); + val = string2words( '4294967298', 10, out, 2, 1 ); + + t.strictEqual( val, out, 'returns expected value' ); + t.strictEqual( val[ 0 ], 0, 'returns expected value' ); + t.strictEqual( val[ 1 ], 1, 'returns expected value' ); + t.strictEqual( val[ 2 ], 0, 'returns expected value' ); + t.strictEqual( val[ 3 ], 2, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.js new file mode 100644 index 000000000000..4eb42e279f95 --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var string2words = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof string2words, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( string2words, 'assign' ), true, 'has property' ); + t.strictEqual( typeof string2words.assign, 'function', 'has method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js new file mode 100644 index 000000000000..8add74716d8b --- /dev/null +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js @@ -0,0 +1,52 @@ +/** +* @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 isInteger = require( '@stdlib/assert/is-integer' ); +var string2words = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof string2words, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a two-element numeric array containing integers', function test( t ) { + var w = string2words( '1234', 10 ); + + t.strictEqual( isInteger( w[0] ), true, 'returns expected value' ); + t.strictEqual( isInteger( w[1] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function parses a string representation of a 64-bit unsigned integer into high and low 32-bit words', function test( t ) { + var w = string2words( '18446744073709551615', 10 ); + + t.strictEqual( w[0], 4294967295, 'returns expected value' ); + t.strictEqual( w[1], 4294967295, 'returns expected value' ); + + t.end(); +}); From bb343370329c548babfe179037bfba1602efa3e8 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 01:53:24 -0700 Subject: [PATCH 02/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index 18d7b1f09a2f..58d5a599e776 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -27,13 +27,13 @@ var TWO_32 = 0x100000000; // 2^32 /** * A flat, strided array containing metadata for parsing large numeric strings into 64-bit values within JavaScript's 53-bit safe integer precision limits. * -* Each radix from 2 to 36 is represented by a 3-element tuple: `[chunk1_len, chunk2_len, multiplier]` +* Each radix from 2 to 36 is represented by a 3-element tuple: `[chunk1_len, chunk2_len, multiplier]`. * * ## Tuple Properties * -* - **chunk1_len**: The maximum number of digits that can be safely parsed in a single pass without exceeding `Number.MAX_SAFE_INTEGER`. -* - **chunk2_len**: The remaining number of digits required to fulfill the maximum width of a 64-bit unsigned integer for that radix. -* - **multiplier**: The positional weight scalar ($radix^{chunk2\_len}$) used to shift the place value of the first chunk when aggregating the final 64-bit split. +* - **chunk1_len**: the maximum number of digits that can be safely parsed in a single pass without exceeding `Number.MAX_SAFE_INTEGER`. +* - **chunk2_len**: the remaining number of digits required to fulfill the maximum width of a 64-bit unsigned integer for that radix. +* - **multiplier**: the positional weight scalar ($radix^{chunk2\_len}$) used to shift the place value of the first chunk when aggregating the final 64-bit split. */ var CHUNKMAP = [ // , , // radix From 7016801c4e7f7d1bbb6ab17531559dc4b77dc5df Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 01:54:34 -0700 Subject: [PATCH 03/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index 58d5a599e776..ab9c4963bed6 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -33,7 +33,7 @@ var TWO_32 = 0x100000000; // 2^32 * * - **chunk1_len**: the maximum number of digits that can be safely parsed in a single pass without exceeding `Number.MAX_SAFE_INTEGER`. * - **chunk2_len**: the remaining number of digits required to fulfill the maximum width of a 64-bit unsigned integer for that radix. -* - **multiplier**: the positional weight scalar ($radix^{chunk2\_len}$) used to shift the place value of the first chunk when aggregating the final 64-bit split. +* - **multiplier**: the positional weight scalar (`radix^chunk2_len`) used to shift the place value of the first chunk when aggregating the final 64-bit split. */ var CHUNKMAP = [ // , , // radix From 994127bffc6aca54ee786bf361d821f20d50bd88 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 01:59:19 -0700 Subject: [PATCH 04/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../uint64/base/string2words/lib/assign.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index ab9c4963bed6..82a98ea3c408 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -77,7 +77,7 @@ var CHUNKMAP = [ /* eslint-enable array-element-newline */ /** -* Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words using two-step chunking.. +* Parses a string representation of a 64-bit unsigned integer into high and low 32-bit words using two-step chunking. * * @private * @param {string} str - string representation of a 64-bit unsigned integer @@ -111,25 +111,24 @@ function chunkedParse( str, radix, len1, len2, mult, out, stride, offset ) { chunk1 = parseInt( str, radix ); } else { // Otherwise use a big chunk1 (start-aligned) and a small chunk2 (end-aligned) - chunk1 = parseInt( str.slice( 0, -len2 ), radix ); // Everything until last `len2` digits + chunk1 = parseInt( str.slice( 0, -len2 ), radix ); // everything until last `len2` digits chunk2 = parseInt( str.slice( -len2 ), radix ); // `len2` digits from the end } - hi = ( chunk1 / TWO_32 ) >>> 0; // Integer division by 2^32 + hi = ( chunk1 / TWO_32 ) >>> 0; // integer division by 2^32 lo = chunk1 >>> 0; // 32-bit truncation - // Process chunk2 if applicable + // Process chunk2 if applicable... if ( str.length > len1 ) { lo = ( lo * mult ) + chunk2; hi = ( hi * mult ) + ( ( lo / TWO_32 ) >>> 0 ); lo >>>= 0; // 32-bit truncation - // Check if too big for uint64 + // Check if too big for uint64... if ( hi >= TWO_32 ) { hi = lo = 0; } } - out[ offset ] = hi; out[ offset + stride ] = lo; return out; @@ -166,9 +165,10 @@ function assign( str, radix, out, stride, offset ) { var mult; var idx; - // Invalid radix + // Check for an invalid radix... if ( !( radix >= 2 && radix <= 36 ) ) { - out[ offset ] = out[ offset + stride ] = 0; + out[ offset ] = 0; + out[ offset + stride ] = 0; return out; } @@ -185,16 +185,14 @@ function assign( str, radix, out, stride, offset ) { out[ offset ] = out[ offset + stride ] = 0; return out; } - - // Fast path for bases 2, 4, and 16, thanks to evenly splittable 32-bit halves + // Fast path for bases 2, 4, and 16, thanks to evenly splittable 32-bit halves: if ( radix === 2 || radix === 4 || radix === 16 ) { len1 = ( len1 + len2 ) / 2; - out[ offset ] = parseInt( '0' + str.slice( 0, -len1 ), radix ); // Adding leading zero in case the higher slice is empty + out[ offset ] = parseInt( '0' + str.slice( 0, -len1 ), radix ); // add leading zero in case the higher slice is empty out[ offset + stride ] = parseInt( str.slice( -len1 ), radix ); return out; } - - // General path for other bases + // General path for other bases: return chunkedParse( str, radix, len1, len2, mult, out, stride, offset ); } From db497b1ce421e06a490a775d07c0c389b0b8b0d1 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:03:44 -0700 Subject: [PATCH 05/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index 82a98ea3c408..b1e325cdd808 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -34,6 +34,10 @@ var TWO_32 = 0x100000000; // 2^32 * - **chunk1_len**: the maximum number of digits that can be safely parsed in a single pass without exceeding `Number.MAX_SAFE_INTEGER`. * - **chunk2_len**: the remaining number of digits required to fulfill the maximum width of a 64-bit unsigned integer for that radix. * - **multiplier**: the positional weight scalar (`radix^chunk2_len`) used to shift the place value of the first chunk when aggregating the final 64-bit split. +* +* @private +* @name CHUNKMAP +* @type {Array} */ var CHUNKMAP = [ // , , // radix From e58c27ff8a4d6135330db83fc2d08c66cb00001f Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:05:14 -0700 Subject: [PATCH 06/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index b1e325cdd808..ca9629f239dc 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -111,10 +111,10 @@ function chunkedParse( str, radix, len1, len2, mult, out, stride, offset ) { var lo; if ( str.length <= len1 ) { - // Parse in a single pass when input length is within chunk1 length + // Parse in a single pass when input length is within chunk1 length: chunk1 = parseInt( str, radix ); } else { - // Otherwise use a big chunk1 (start-aligned) and a small chunk2 (end-aligned) + // Otherwise use a big chunk1 (start-aligned) and a small chunk2 (end-aligned): chunk1 = parseInt( str.slice( 0, -len2 ), radix ); // everything until last `len2` digits chunk2 = parseInt( str.slice( -len2 ), radix ); // `len2` digits from the end } @@ -184,12 +184,12 @@ function assign( str, radix, out, stride, offset ) { len2 = CHUNKMAP[ idx+1 ]; mult = CHUNKMAP[ idx+2 ]; - // Check if too big for uint64: + // Check if too big for uint64... if ( str.length > len1+len2 ) { out[ offset ] = out[ offset + stride ] = 0; return out; } - // Fast path for bases 2, 4, and 16, thanks to evenly splittable 32-bit halves: + // Fast path for bases 2, 4, and 16, thanks to evenly splittable 32-bit halves... if ( radix === 2 || radix === 4 || radix === 16 ) { len1 = ( len1 + len2 ) / 2; out[ offset ] = parseInt( '0' + str.slice( 0, -len1 ), radix ); // add leading zero in case the higher slice is empty From 0bc430229f2c9ab1c0babd46742cbc43ad562d9e Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:06:05 -0700 Subject: [PATCH 07/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index ca9629f239dc..243a1cc6924a 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -130,7 +130,8 @@ function chunkedParse( str, radix, len1, len2, mult, out, stride, offset ) { // Check if too big for uint64... if ( hi >= TWO_32 ) { - hi = lo = 0; + hi = 0; + lo = 0; } } out[ offset ] = hi; From 36f9f164c59093e32200f5e3d981c74e265cc1d9 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:07:14 -0700 Subject: [PATCH 08/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index 243a1cc6924a..abc4062f0d79 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -171,7 +171,7 @@ function assign( str, radix, out, stride, offset ) { var idx; // Check for an invalid radix... - if ( !( radix >= 2 && radix <= 36 ) ) { + if ( radix < 2 || radix > 36 ) ) { out[ offset ] = 0; out[ offset + stride ] = 0; return out; From 9b6b6aea3c61eaaada7483cb9b16f13b9b9c7cdc Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:07:40 -0700 Subject: [PATCH 09/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index abc4062f0d79..742e12ce3267 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -176,7 +176,6 @@ function assign( str, radix, out, stride, offset ) { out[ offset + stride ] = 0; return out; } - // Compute the index into a pre-computed strided table: idx = 3 * ( radix-2 ); From 65382cbf8d2659a1c64c83b491c1878a266c4c47 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:08:16 -0700 Subject: [PATCH 10/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index 742e12ce3267..93d1d97cb409 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -186,7 +186,8 @@ function assign( str, radix, out, stride, offset ) { // Check if too big for uint64... if ( str.length > len1+len2 ) { - out[ offset ] = out[ offset + stride ] = 0; + out[ offset ] = 0; + out[ offset + stride ] = 0; return out; } // Fast path for bases 2, 4, and 16, thanks to evenly splittable 32-bit halves... From 96f68054c69bb16fe6e8121dea839616663f9462 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:09:16 -0700 Subject: [PATCH 11/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/main.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js index c607682499a9..27a9fb078b76 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/main.js @@ -23,9 +23,6 @@ var assign = require( './assign.js' ); -// MAIN // - - // MAIN // /** From 9c24656ccd69057908635a736d50484cf2ef935d Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:11:45 -0700 Subject: [PATCH 12/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/test/test.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js index 20091e66f539..90925897d959 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js @@ -24,7 +24,7 @@ var tape = require( 'tape' ); var Uint32Array = require( '@stdlib/array/uint32' ); var hasBigIntSupport = require( '@stdlib/assert/has-bigint-support' ); var isEqualArray = require( '@stdlib/assert/is-equal-array' ); -var isInteger = require( '@stdlib/assert/is-integer' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var BigInt = require( '@stdlib/bigint/ctor' ); var toWords = require( '@stdlib/number/uint64/base/to-words' ); var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); From f62216cd86b3fcaf2a5c5af61f0e94029543d1eb Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:12:19 -0700 Subject: [PATCH 13/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/test/test.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js index 8add74716d8b..5b128016ec7a 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.main.js @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var isInteger = require( '@stdlib/assert/is-integer' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var string2words = require( './../lib/main.js' ); From 54332d7ea63d530245f97629404eb0732794414f Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:13:52 -0700 Subject: [PATCH 14/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md b/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md index 917d7b3b2dea..aabf5312da17 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/README.md @@ -79,7 +79,7 @@ var bool = ( w === out ); ## Notes - The input string must be a valid representation of an unsigned 64-bit integer in the specified radix, containing no whitespace, sign symbols, or leading zeros. -- If the provided string represents a value greater than `2^64-1` or the radix is invalid then `0` is assigned to both high and low words. +- If the provided string represents a value greater than `2^64-1` or the radix is invalid, then `0` is assigned to both high and low words. From 766c4bf11180d35b12e4f14c58ec491b3022d442 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 7 Jul 2026 02:15:42 -0700 Subject: [PATCH 15/16] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/number/uint64/base/string2words/lib/assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js index 93d1d97cb409..1f0ac8f5cdb9 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/lib/assign.js @@ -171,7 +171,7 @@ function assign( str, radix, out, stride, offset ) { var idx; // Check for an invalid radix... - if ( radix < 2 || radix > 36 ) ) { + if ( radix < 2 || radix > 36 ) { out[ offset ] = 0; out[ offset + stride ] = 0; return out; From 0621ec6d9471ae8c1622bbfb5a94a40872335eab Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Tue, 7 Jul 2026 17:02:02 +0600 Subject: [PATCH 16/16] test: add too big number and invalid radix tests --- 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: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../base/string2words/test/test.assign.js | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js index 90925897d959..e088fbffd426 100644 --- a/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js +++ b/lib/node_modules/@stdlib/number/uint64/base/string2words/test/test.assign.js @@ -171,6 +171,72 @@ tape( 'the function parses a string representation of a 64-bit unsigned integer t.end(); }); +tape( 'the function assigns 0 to both high and low words if the provided string represents a value greater than 2^64-1', function test( t ) { + var expected; + var values; + var out; + var rad; + var i; + var s; + var w; + + values = [ + '0x10000000000000000', + '0x10000000000000001', + '0x123456789abcdef01', + '0xdeadbeef15badf00d', + '0x1337c0de4ce5b16b055', + '0x123456789abcdef0123456789abcdef0' + ]; + + expected = [ 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + values[ i ] = BigInt( values[ i ] ); // Convert to BigInt + + for ( rad = 2; rad <= 36; rad++ ) { + s = values[ i ].toString( rad ); // Convert BigInt to string with a radix + out = [ 1, 1 ]; // To observe that it gets changed + w = string2words( s, rad, out, 1, 0 ); // Extract words from the string reperesentation + + t.ok( isEqualArray( w, expected ), 'returns expected value' ); + t.strictEqual( w, out, 'returns expected value' ); + } + } + + t.end(); +}); + +tape( 'the function assigns 0 to both high and low words if provided an invalid radix', function test( t ) { + var expected; + var values; + var out; + var rad; + var i; + var w; + + values = [ + 0, + 1, + 37, + 38, + 100 + ]; + + expected = [ 0, 0 ]; + + for ( i = 0; i < values.length; i++ ) { + rad = values[ i ]; + out = [ 1, 1 ]; // To observe that it gets changed + w = string2words( '10', rad, out, 1, 0 ); + + t.ok( isEqualArray( w, expected ), 'returns expected value' ); + t.strictEqual( w, out, 'returns expected value' ); + } + + t.end(); +}); + tape( 'the function supports providing an output object (array)', function test( t ) { var out; var w;