-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add uint64/base/number2words
#13250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kgryte
merged 8 commits into
stdlib-js:develop
from
impawstarlight:feature/uint64-base-number2words
Jul 4, 2026
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d00d948
feat: add `uint64/base/number2words`
impawstarlight 38d165c
Apply suggestions from code review
kgryte f239c13
Apply suggestions from code review
kgryte c1b9ff3
Apply suggestions from code review
kgryte 2e9b460
Apply suggestions from code review
kgryte 9a018ea
Apply suggestions from code review
kgryte 702a005
Apply suggestions from code review
kgryte e196e26
Apply suggestions from code review
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
lib/node_modules/@stdlib/number/uint64/base/number2words/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # number2words | ||
|
|
||
| > Split a number into the high and low 32-bit words of a 64-bit unsigned integer. | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- Package usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var number2words = require( '@stdlib/number/uint64/base/number2words' ); | ||
| ``` | ||
|
|
||
| #### number2words( value ) | ||
|
|
||
| Splits a number into the high and low 32-bit words of a 64-bit unsigned integer. | ||
|
|
||
| ```javascript | ||
| var w = number2words( 1234 ); | ||
| // 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. | ||
|
|
||
| #### number2words.assign( value, out, stride, offset ) | ||
|
|
||
| Splits a number into the high and low 32-bit words of a 64-bit unsigned integer and assigns results to a provided output array. | ||
|
|
||
| ```javascript | ||
| var Uint32Array = require( '@stdlib/array/uint32' ); | ||
|
|
||
| var out = new Uint32Array( 2 ); | ||
| // returns <Uint32Array>[ 0, 0 ] | ||
|
|
||
| var w = number2words.assign( 9007199254740991, out, 1, 0 ); | ||
| // returns <Uint32Array>[ 2097151, 4294967295 ] | ||
|
|
||
| var bool = ( w === out ); | ||
| // returns true | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| * * * | ||
|
|
||
| <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - For accurate results, the input value should be an integer in the range \[`0`, `2^53-1`\]. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| * * * | ||
|
|
||
|
kgryte marked this conversation as resolved.
Outdated
|
||
| <!-- Package usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| ```javascript | ||
| var number2words = require( '@stdlib/number/uint64/base/number2words' ); | ||
|
|
||
| var w = number2words( 1234 ); | ||
| console.log( w ); | ||
| // => [ 0, 1234 ] | ||
|
|
||
| w = number2words( 0x100000000 ); | ||
| console.log( w ); | ||
| // => [ 1, 0 ] | ||
|
|
||
| w = number2words( 9007199254740991 ); | ||
| console.log( w ); | ||
| // => [ 2097151, 4294967295 ] | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| <!-- <related-links> --> | ||
|
|
||
| <!-- </related-links> --> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
84 changes: 84 additions & 0 deletions
84
lib/node_modules/@stdlib/number/uint64/base/number2words/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * @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 MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); | ||
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var number2words = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var values; | ||
| var N; | ||
| var i; | ||
| var w; | ||
|
|
||
| N = 100; | ||
| values = discreteUniform( N, 0, MAX_SAFE_INTEGER ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| w = number2words( values[ 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 values; | ||
| var out; | ||
| var N; | ||
| var i; | ||
| var w; | ||
|
|
||
| N = 100; | ||
| values = discreteUniform( N, 0, MAX_SAFE_INTEGER ); | ||
|
|
||
| out = new Uint32Array( 2 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| w = number2words.assign( values[ 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(); | ||
| }); |
59 changes: 59 additions & 0 deletions
59
lib/node_modules/@stdlib/number/uint64/base/number2words/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
|
|
||
| {{alias}}( value ) | ||
| Splits a number into the high and low 32-bit words of a 64-bit unsigned | ||
| integer. | ||
|
|
||
| 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 | ||
| ---------- | ||
| value: integer | ||
| Integer value in the range [0, 2^53-1]. | ||
|
|
||
| Returns | ||
| ------- | ||
| out: Array<integer> | ||
| High and low words as 32-bit unsigned integers. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var w = {{alias}}( 1234 ) | ||
| [ 0, 1234 ] | ||
|
|
||
|
|
||
| {{alias}}.assign( value, out, stride, offset ) | ||
| Splits a number into the high and low 32-bit words of a 64-bit unsigned | ||
| integer and assigns results to a provided output array. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| value: integer | ||
| Integer value in the range [0, 2^53-1]. | ||
|
|
||
| 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( 9007199254740991, out, 1, 0 ) | ||
| <Uint32Array>[ 2097151, 4294967295 ] | ||
| > var bool = ( w === out ) | ||
| true | ||
|
|
||
| See Also | ||
| -------- |
104 changes: 104 additions & 0 deletions
104
lib/node_modules/@stdlib/number/uint64/base/number2words/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * @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 | ||
|
|
||
| /// <reference types="@stdlib/types"/> | ||
|
|
||
| import { Collection, NumericArray } from '@stdlib/types/array'; | ||
|
|
||
| /** | ||
| * Interface describing `number2words`. | ||
| */ | ||
| interface NumberToWords { | ||
| /** | ||
| * Splits a number into the high and low 32-bit words of a 64-bit unsigned integer. | ||
| * | ||
| * @param value - integer value in the range [0, 2^53-1] | ||
| * @returns high and low words as 32-bit unsigned integers | ||
| * | ||
| * @example | ||
| * var out = number2words( 1234 ); | ||
| * // returns [ 0, 1234 ] | ||
| * | ||
| * out = number2words( 0x100000000 ); | ||
| * // returns [ 1, 0 ] | ||
| * | ||
| * out = number2words( 9007199254740991 ); | ||
| * // returns [ 2097151, 4294967295 ] | ||
| */ | ||
| ( value: number ): [ number, number ]; | ||
|
|
||
| /** | ||
| * Splits a number into the high and low 32-bit words of a 64-bit unsigned integer and assigns results to a provided output array. | ||
| * | ||
| * @param value - integer value in the range [0, 2^53-1] | ||
| * @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 <Uint32Array>[ 0, 0 ] | ||
| * | ||
| * var w = number2words.assign( 9007199254740991, out, 1, 0 ); | ||
| * // returns <Uint32Array>[ 2097151, 4294967295 ] | ||
| * | ||
| * var bool = ( w === out ); | ||
| * // returns true | ||
| */ | ||
| assign<T extends NumericArray | Collection<number>>( value: number, out: T, stride: number, offset: number ): T; | ||
| } | ||
|
|
||
| /** | ||
| * Splits a number into the high and low 32-bit words of a 64-bit unsigned integer. | ||
| * | ||
| * @param value - integer value in the range [0, 2^53-1] | ||
| * @returns high and low words as 32-bit unsigned integers | ||
| * | ||
| * @example | ||
| * var out = number2words( 1234 ); | ||
| * // returns [ 0, 1234 ] | ||
| * | ||
| * out = number2words( 0x100000000 ); | ||
| * // returns [ 1, 0 ] | ||
| * | ||
| * out = number2words( 9007199254740991 ); | ||
| * // returns [ 2097151, 4294967295 ] | ||
| * | ||
| * @example | ||
| * var Uint32Array = require( '@stdlib/array/uint32' ); | ||
| * | ||
| * var out = new Uint32Array( 2 ); | ||
| * // returns <Uint32Array>[ 0, 0 ] | ||
| * | ||
| * var w = number2words.assign( 9007199254740991, out, 1, 0 ); | ||
| * // returns <Uint32Array>[ 2097151, 4294967295 ] | ||
| * | ||
| * var bool = ( w === out ); | ||
| * // returns true | ||
| */ | ||
| declare var number2words: NumberToWords; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = number2words; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.