-
-
Notifications
You must be signed in to change notification settings - Fork 993
feat: add number/float16/base/from-word
#8733
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
Open
gururaj1512
wants to merge
9
commits into
stdlib-js:develop
Choose a base branch
from
gururaj1512:number-float16-base-from-word
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+926
−0
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f41dcf
feat: add number/float16/base/from-word
gururaj1512 c6cbc29
feat: add repl
gururaj1512 32f3fb3
chore: update copyright years
stdlib-bot 848bd84
Merge remote-tracking branch 'upstream/develop' into number-float16-b…
stdlib-bot 9723c15
refactor: use standalone constants
gururaj1512 85fece5
Merge remote-tracking branch 'upstream/develop' into number-float16-b…
stdlib-bot c6f8fea
docs: remove comment
kgryte 8877a61
docs: remove backticks
kgryte 1f03454
chore: apply suggested changes
gururaj1512 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
104 changes: 104 additions & 0 deletions
104
lib/node_modules/@stdlib/number/float16/base/from-word/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,104 @@ | ||
| <!-- | ||
| @license Apache-2.0 | ||
| Copyright (c) 2025 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. | ||
| --> | ||
|
|
||
| # fromWord | ||
|
|
||
| > Create a [half-precision floating-point number][ieee754] from an unsigned integer corresponding to an [IEEE 754][ieee754] binary representation. | ||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var fromWord = require( '@stdlib/number/float16/base/from-word' ); | ||
| ``` | ||
|
|
||
| #### fromWord( word ) | ||
|
|
||
| Creates a [half-precision floating-point number][ieee754] from an unsigned `integer` corresponding to an [IEEE 754][ieee754] binary representation. | ||
|
|
||
| ```javascript | ||
| var word = 15411; // => 0 01111 0000110011 | ||
|
|
||
| var f16 = fromWord( word ); // when printed, implicitly promoted to float64 | ||
| // returns 1.0498046875 | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var round = require( '@stdlib/math/base/special/round' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var naryFunction = require( '@stdlib/utils/nary-function' ); | ||
| var pickArguments = require( '@stdlib/utils/pick-arguments' ); | ||
| var logEachMap = require( '@stdlib/console/log-each-map' ); | ||
| var MAX_UINT16 = require( '@stdlib/constants/uint16/max' ); | ||
| var fromWord = require( '@stdlib/number/float16/base/from-word' ); | ||
|
|
||
| // Generate an array of random numbers: | ||
| var arr = uniform( 1000, 0.0, MAX_UINT16 ); | ||
|
|
||
| // Round each number: | ||
| var word = map( arr, naryFunction( round, 1 ) ); | ||
gururaj1512 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Create half-precision floating-point numbers from unsigned integers... | ||
| logEachMap( 'word: %d => float16: %f', word, pickArguments( fromWord, [ 0 ] ) ); | ||
| ``` | ||
|
|
||
| </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"> | ||
|
|
||
| [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 | ||
|
|
||
| <!-- <related-links> --> | ||
|
|
||
| <!-- </related-links> --> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
58 changes: 58 additions & 0 deletions
58
lib/node_modules/@stdlib/number/float16/base/from-word/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,58 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' ); | ||
| var round = require( '@stdlib/math/base/special/round' ); | ||
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var naryFunction = require( '@stdlib/utils/nary-function' ); | ||
| var MAX_UINT16 = require( '@stdlib/constants/uint16/max' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var fromWord = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var word; | ||
| var x; | ||
| var y; | ||
| var i; | ||
|
|
||
| x = uniform( 100, 0.0, MAX_UINT16 ); | ||
gururaj1512 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| word = map( x, naryFunction( round, 1 ) ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| y = fromWord( word ); | ||
| if ( isnan( y ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( y ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
24 changes: 24 additions & 0 deletions
24
lib/node_modules/@stdlib/number/float16/base/from-word/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,24 @@ | ||
|
|
||
| {{alias}}( word ) | ||
| Creates a half-precision floating-point number from an unsigned integer | ||
| corresponding to an IEEE 754 binary representation. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| word: integer | ||
| Unsigned integer. | ||
|
|
||
| Returns | ||
| ------- | ||
| out: float | ||
| Half-precision floating-point number. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var word = 15411; // => 0 01111 0000110011 | ||
| > var f16 = {{alias}}( word ) // when printed, promoted to float64 | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 1.0498046875 | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
38 changes: 38 additions & 0 deletions
38
lib/node_modules/@stdlib/number/float16/base/from-word/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,38 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2025 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 | ||
|
|
||
| /** | ||
| * Creates a half-precision floating-point number from an unsigned integer corresponding to an IEEE 754 binary representation. | ||
| * | ||
| * @param word - unsigned integer | ||
| * @returns half-precision floating-point number | ||
| * | ||
| * @example | ||
| * var word = 15411; // => 0 01111 0000110011 | ||
| * | ||
| * var f16 = fromWord( word ); // when printed, implicitly promoted to float64 | ||
| * // returns 1.0498046875 | ||
| */ | ||
| declare function fromWord( word: number ): number; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = fromWord; |
42 changes: 42 additions & 0 deletions
42
lib/node_modules/@stdlib/number/float16/base/from-word/docs/types/test.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,42 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2025 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 fromWord = require( './index' ); | ||
|
|
||
|
|
||
| // TESTS // | ||
|
|
||
| // The function returns a number... | ||
| { | ||
| fromWord( 15411 ); // $ExpectType number | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided a value other than a number... | ||
| { | ||
| fromWord( true ); // $ExpectError | ||
| fromWord( false ); // $ExpectError | ||
| fromWord( 'abc' ); // $ExpectError | ||
| fromWord( [] ); // $ExpectError | ||
| fromWord( {} ); // $ExpectError | ||
| fromWord( ( x: number ): number => x ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided insufficient arguments... | ||
| { | ||
| fromWord(); // $ExpectError | ||
| } |
37 changes: 37 additions & 0 deletions
37
lib/node_modules/@stdlib/number/float16/base/from-word/examples/index.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,37 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' ); | ||
| var round = require( '@stdlib/math/base/special/round' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var naryFunction = require( '@stdlib/utils/nary-function' ); | ||
| var pickArguments = require( '@stdlib/utils/pick-arguments' ); | ||
| var logEachMap = require( '@stdlib/console/log-each-map' ); | ||
| var MAX_UINT16 = require( '@stdlib/constants/uint16/max' ); | ||
| var fromWord = require( './../lib' ); | ||
|
|
||
| // Generate an array of random numbers: | ||
| var arr = uniform( 1000, 0.0, MAX_UINT16 ); | ||
gururaj1512 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Round each number: | ||
| var word = map( arr, naryFunction( round, 1 ) ); | ||
|
|
||
| // Create half-precision floating-point numbers from unsigned integers... | ||
| logEachMap( 'word: %d => float16: %f', word, pickArguments( fromWord, [ 0 ] ) ); | ||
42 changes: 42 additions & 0 deletions
42
lib/node_modules/@stdlib/number/float16/base/from-word/lib/index.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,42 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2025 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'; | ||
|
|
||
| /** | ||
| * Create a half-precision floating-point number from an unsigned integer corresponding to an IEEE 754 binary representation. | ||
| * | ||
| * @module @stdlib/number/float16/base/from-word | ||
| * | ||
| * @example | ||
| * var fromWord = require( '@stdlib/number/float16/base/from-word' ); | ||
| * | ||
| * var word = 15411; // => 0 01111 0000110011 | ||
| * | ||
| * var f16 = fromWord( word ); // when printed, implicitly promoted to float64 | ||
| * // returns 1.0498046875 | ||
| */ | ||
|
|
||
| // MODULES // | ||
|
|
||
| var main = require( './main.js' ); | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = main; |
Oops, something went wrong.
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.