-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add number/float16/base/div
#9454
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
Lokeshranjan8
wants to merge
17
commits into
stdlib-js:develop
Choose a base branch
from
Lokeshranjan8:for-loop-utils
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.
+742
−0
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e8eb608
feat: add number/float16/base/div
Lokeshranjan8 05046ef
Update copyright year from 2023 to 2025
Lokeshranjan8 d8223e6
Clean up package.json by removing gypfile and directories
Lokeshranjan8 e3bf011
Update lib/node_modules/@stdlib/number/float16/base/div/lib/main.js
Lokeshranjan8 fac1a34
Update lib/node_modules/@stdlib/number/float16/base/div/README.md
Lokeshranjan8 87007ea
bench: generate half-precision inputs using uniform distribution
Lokeshranjan8 a213d16
bench: wrap toFloat16 with naryFunction in map
Lokeshranjan8 7f4dee6
Revise div function documentation for clarity
Lokeshranjan8 316495f
Update lib/node_modules/@stdlib/number/float16/base/div/package.json
Lokeshranjan8 d0e2844
Update lib/node_modules/@stdlib/number/float16/base/div/package.json
Lokeshranjan8 d9b54f1
Update lib/node_modules/@stdlib/number/float16/base/div/examples/inde…
Lokeshranjan8 9ebade0
Update lib/node_modules/@stdlib/number/float16/base/div/examples/inde…
Lokeshranjan8 1aee25c
Update lib/node_modules/@stdlib/number/float16/base/div/README.md
Lokeshranjan8 ee0a4db
Update lib/node_modules/@stdlib/number/float16/base/div/test/test.js
Lokeshranjan8 7284e19
Update lib/node_modules/@stdlib/number/float16/base/div/docs/types/in…
Lokeshranjan8 3cfe186
Update lib/node_modules/@stdlib/number/float16/base/div/package.json
Lokeshranjan8 33139bd
Update test.js
Lokeshranjan8 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
115 changes: 115 additions & 0 deletions
115
lib/node_modules/@stdlib/number/float16/base/div/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,115 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # div | ||
|
|
||
| > Divide two half-precision floating-point numbers. | ||
|
|
||
| <!-- 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 div = require( '@stdlib/number/float16/base/div' ); | ||
| ``` | ||
|
|
||
| #### div( x, y ) | ||
|
|
||
| Divides two half-precision floating-point numbers. | ||
|
|
||
| ```javascript | ||
| var v = div( -1.0, 5.0 ); | ||
| // returns ~-0.2 | ||
|
|
||
| v = div( 2.0, 5.0 ); | ||
| // returns ~0.4 | ||
|
|
||
| v = div( 0.0, 5.0 ); | ||
| // returns 0.0 | ||
|
|
||
| v = div( -0.0, 5.0 ); | ||
| // returns -0.0 | ||
|
|
||
| v = div( NaN, NaN ); | ||
| // returns NaN | ||
| ``` | ||
|
|
||
| </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"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <!-- Package usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var logEachMap = require( '@stdlib/console/log-each-map' ); | ||
| var div = require( '@stdlib/number/float16/base/div' ); | ||
|
|
||
| var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); | ||
| var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); | ||
|
|
||
| logEachMap( 'x: %0.4f, y: %0.4f => div: %0.4f', x, y, div ); | ||
| ``` | ||
|
|
||
| </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"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> |
57 changes: 57 additions & 0 deletions
57
lib/node_modules/@stdlib/number/float16/base/div/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,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'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); | ||
| var isnan = require( '@stdlib/math/base/assert/is-nanf' ); | ||
| var naryFunction = require( '@stdlib/utils/nary-function' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var div = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var out; | ||
| var x; | ||
| var y; | ||
| var i; | ||
|
|
||
| x = map( uniform( 100, -100, 100 ), naryFunction( toFloat16, 1 ) ); | ||
| y = map( uniform( 100, -100, 100 ), naryFunction( toFloat16, 1 ) ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| out = div( x[ i%x.length ], y[ i%y.length ] ); | ||
| if ( isnan( out ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( out ) ) { | ||
| b.fail( 'should not return NaN' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
33 changes: 33 additions & 0 deletions
33
lib/node_modules/@stdlib/number/float16/base/div/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,33 @@ | ||
|
|
||
| {{alias}}( x, y ) | ||
| Divides two half-precision floating-point numbers. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| x: number | ||
| First input value (dividend). | ||
|
|
||
| y: number | ||
| Second input value (divisor). | ||
|
|
||
| Returns | ||
| ------- | ||
| z: number | ||
| Result. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var v = {{alias}}( -1.0, 5.0 ) | ||
| ~-0.2 | ||
| > v = {{alias}}( 2.0, 5.0 ) | ||
| ~0.4 | ||
| > v = {{alias}}( 0.0, 5.0 ) | ||
| 0.0 | ||
| > v = {{alias}}( -0.0, 5.0 ) | ||
| -0.0 | ||
| > v = {{alias}}( NaN, NaN ) | ||
| NaN | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
53 changes: 53 additions & 0 deletions
53
lib/node_modules/@stdlib/number/float16/base/div/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,53 @@ | ||
| /* | ||
| * @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 | ||
|
|
||
| /** | ||
| * Divides two half-precision floating-point numbers. | ||
| * | ||
| * @param x - first input value | ||
| * @param y - second input value | ||
| * @returns result | ||
| * | ||
| * @example | ||
| * var v = div( -1.0, 5.0 ); | ||
| * // returns ~-0.2 | ||
| * | ||
| * @example | ||
| * var v = div( 2.0, 5.0 ); | ||
| * // returns ~0.4 | ||
| * | ||
| * @example | ||
| * var v = div( 0.0, 5.0 ); | ||
| * // returns 0.0 | ||
| * | ||
| * @example | ||
| * var v = div( -0.0, 5.0 ); | ||
| * // returns -0.0 | ||
| * | ||
| * @example | ||
| * var v = div( NaN, NaN ); | ||
| * // returns NaN | ||
| */ | ||
| declare function div( x: number, y: number ): number; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = div; | ||
58 changes: 58 additions & 0 deletions
58
lib/node_modules/@stdlib/number/float16/base/div/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,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. | ||
| */ | ||
|
|
||
| import div = require( './index' ); | ||
|
|
||
|
|
||
| // TESTS // | ||
|
|
||
| // The function returns a number... | ||
| { | ||
| div( 8.0, 8.0 ); // $ExpectType number | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided a first argument which is not a number... | ||
| { | ||
| div( true, 5.0 ); // $ExpectError | ||
| div( false, 5.0 ); // $ExpectError | ||
| div( null, 5.0 ); // $ExpectError | ||
| div( undefined, 5.0 ); // $ExpectError | ||
| div( '5', 5.0 ); // $ExpectError | ||
| div( [], 5.0 ); // $ExpectError | ||
| div( {}, 5.0 ); // $ExpectError | ||
| div( ( x: number ): number => x, 5.0 ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided a second argument which is not a number... | ||
| { | ||
| div( 5.0, true ); // $ExpectError | ||
| div( 5.0, false ); // $ExpectError | ||
| div( 5.0, null ); // $ExpectError | ||
| div( 5.0, undefined ); // $ExpectError | ||
| div( 5.0, '5' ); // $ExpectError | ||
| div( 5.0, [] ); // $ExpectError | ||
| div( 5.0, {} ); // $ExpectError | ||
| div( 5.0, ( x: number ): number => x ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided an unsupported number of arguments... | ||
| { | ||
| div(); // $ExpectError | ||
| div( 5.0 ); // $ExpectError | ||
| div( 5.0, 5.0, 5.0 ); // $ExpectError | ||
| } |
30 changes: 30 additions & 0 deletions
30
lib/node_modules/@stdlib/number/float16/base/div/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,30 @@ | ||
| /** | ||
| * @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 toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var logEachMap = require( '@stdlib/console/log-each-map' ); | ||
| var div = require( './../lib' ); | ||
|
|
||
| var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); | ||
| var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); | ||
|
|
||
| logEachMap( 'x: %0.4f, y: %0.4f => div: %0.4f', x, y, div ); |
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.