From bc488438696f290bc723ce2bed66f99a33c1e7e5 Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Tue, 30 Dec 2025 23:04:17 +0530 Subject: [PATCH 01/17] feat: adding initial js implementation --- .../@stdlib/number/float16/base/add/README.md | 135 +++++++++++++ .../float16/base/add/benchmark/benchmark.js | 57 ++++++ .../number/float16/base/add/docs/repl.txt | 33 ++++ .../float16/base/add/docs/types/index.d.ts | 53 +++++ .../float16/base/add/docs/types/test.ts | 58 ++++++ .../number/float16/base/add/examples/index.js | 34 ++++ .../number/float16/base/add/lib/index.js | 52 +++++ .../number/float16/base/add/lib/main.js | 62 ++++++ .../number/float16/base/add/package.json | 183 ++++++++++++++++++ .../number/float16/base/add/test/test.js | 82 ++++++++ 10 files changed, 749 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/README.md create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/examples/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/lib/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/lib/main.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/package.json create mode 100644 lib/node_modules/@stdlib/number/float16/base/add/test/test.js diff --git a/lib/node_modules/@stdlib/number/float16/base/add/README.md b/lib/node_modules/@stdlib/number/float16/base/add/README.md new file mode 100644 index 000000000000..cd58c1ebf023 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/README.md @@ -0,0 +1,135 @@ + + +# add + +> Compute the sum of two half-precision floating-point numbers. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var add = require( '@stdlib/number/float16/base/add' ); +``` + +#### add( x, y ) + +Computes the sum of two half-precision floating-point numbers. + +```javascript +var v = add( -1.0, 5.0 ); +// returns 4.0 + +v = add( 2.0, 5.0 ); +// returns 7.0 + +v = add( 0.0, 5.0 ); +// returns 5.0 + +v = add( -0.0, 0.0 ); +// returns 0.0 + +v = add( NaN, NaN ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```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 add = require( '@stdlib/number/float16/base/add' ); + +// Create an array of random half-precision floating-point numbers: +var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); + +// Create an array of random half-precision floating-point numbers: +var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); + +// Determine whether the sum of each number: +logEachMap( 'x: %0.4f, y: %0.4f => %0.4f', x, y, add ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js new file mode 100644 index 000000000000..839efa4be2a5 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var map = require( '@stdlib/array/base/map' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var pkg = require( './../package.json' ).name; +var add = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var x; + var y; + var i; + + x = map( uniform( 100, -5.0e4, 5.0e4 ), naryFunction( toFloat16, 1 ) ); + y = map( uniform( 100, -5.0e4, 5.0e4 ), naryFunction( toFloat16, 1 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = add( 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(); +}); diff --git a/lib/node_modules/@stdlib/number/float16/base/add/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/base/add/docs/repl.txt new file mode 100644 index 000000000000..735860a6463e --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x, y ) + Computes the sum of two half-precision floating-point numbers `x` and `y`. + + Parameters + ---------- + x: number + First input value. + + y: number + Second input value. + + Returns + ------- + z: number + Sum. + + Examples + -------- + > var v = {{alias}}( -1.0, 5.0 ) + 4.0 + > v = {{alias}}( 2.0, 5.0 ) + 7.0 + > v = {{alias}}( 0.0, 5.0 ) + 5.0 + > v = {{alias}}( -0.0, 0.0 ) + 0.0 + > v = {{alias}}( NaN, NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/float16/base/add/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/base/add/docs/types/index.d.ts new file mode 100644 index 000000000000..84f97d2ae4bc --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/docs/types/index.d.ts @@ -0,0 +1,53 @@ +/* +* @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 + +/** +* Computes the sum of two half-precision floating-point numbers `x` and `y`. +* +* @param x - first input value +* @param y - second input value +* @returns sum +* +* @example +* var v = add( -1.0, 5.0 ); +* // returns 4.0 +* +* @example +* var v = add( 2.0, 5.0 ); +* // returns 7.0 +* +* @example +* var v = add( 0.0, 5.0 ); +* // returns 5.0 +* +* @example +* var v = add( -0.0, 0.0 ); +* // returns 0.0 +* +* @example +* var v = add( NaN, NaN ); +* // returns NaN +*/ +declare function add( x: number, y: number ): number; + + +// EXPORTS // + +export = add; diff --git a/lib/node_modules/@stdlib/number/float16/base/add/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/base/add/docs/types/test.ts new file mode 100644 index 000000000000..10bdb148bd4e --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/docs/types/test.ts @@ -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. +*/ + +import add = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + add( 8.0, 8.0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + add( true, 5.0 ); // $ExpectError + add( false, 5.0 ); // $ExpectError + add( null, 5.0 ); // $ExpectError + add( undefined, 5.0 ); // $ExpectError + add( '5', 5.0 ); // $ExpectError + add( [], 5.0 ); // $ExpectError + add( {}, 5.0 ); // $ExpectError + add( ( 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... +{ + add( 5.0, true ); // $ExpectError + add( 5.0, false ); // $ExpectError + add( 5.0, null ); // $ExpectError + add( 5.0, undefined ); // $ExpectError + add( 5.0, '5' ); // $ExpectError + add( 5.0, [] ); // $ExpectError + add( 5.0, {} ); // $ExpectError + add( 5.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + add(); // $ExpectError + add( 5.0 ); // $ExpectError + add( 5.0, 5.0, 5.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js b/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js new file mode 100644 index 000000000000..5e35457c1ea3 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 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 add = require( './../lib' ); + +// Create an array of random half-precision floating-point numbers: +var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); + +// Create an array of random half-precision floating-point numbers: +var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); + +// Determine whether the sum of each number: +logEachMap( 'x: %0.4f, y: %0.4f => %0.4f', x, y, add ); diff --git a/lib/node_modules/@stdlib/number/float16/base/add/lib/index.js b/lib/node_modules/@stdlib/number/float16/base/add/lib/index.js new file mode 100644 index 000000000000..7d4082769770 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/lib/index.js @@ -0,0 +1,52 @@ +/** +* @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'; + +/** +* Compute the sum of two half-precision floating-point numbers. +* +* @module @stdlib/number/float16/base/add +* +* @example +* var add = require( '@stdlib/number/float16/base/add' ); +* +* var v = add( -1.0, 5.0 ); +* // returns 4.0 +* +* v = add( 2.0, 5.0 ); +* // returns 7.0 +* +* v = add( 0.0, 5.0 ); +* // returns 5.0 +* +* v = add( -0.0, 0.0 ); +* // returns 0.0 +* +* v = add( NaN, NaN ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/float16/base/add/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/add/lib/main.js new file mode 100644 index 000000000000..2c9e99ddf663 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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 float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); + + +// MAIN // + +/** +* Computes the sum of two half-precision floating-point numbers `x` and `y`. +* +* @param {number} x - first input value +* @param {number} y - second input value +* @returns {number} sum +* +* @example +* var v = add( -1.0, 5.0 ); +* // returns 4.0 +* +* @example +* var v = add( 2.0, 5.0 ); +* // returns 7.0 +* +* @example +* var v = add( 0.0, 5.0 ); +* // returns 5.0 +* +* @example +* var v = add( -0.0, 0.0 ); +* // returns 0.0 +* +* @example +* var v = add( NaN, NaN ); +* // returns NaN +*/ +function add( x, y ) { + return float64ToFloat16( float64ToFloat16( x ) + float64ToFloat16( y ) ); +} + + +// EXPORTS // + +module.exports = add; diff --git a/lib/node_modules/@stdlib/number/float16/base/add/package.json b/lib/node_modules/@stdlib/number/float16/base/add/package.json new file mode 100644 index 000000000000..7ee7f2a49e88 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/package.json @@ -0,0 +1,183 @@ +{ + "name": "@stdlib/number/float16/base/add", + "version": "0.0.0", + "description": "Compute the sum of two half-precision floating-point numbers.", + "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", + "stdmath", + "mathematics", + "math", + "sum", + "add", + "addition", + "summation", + "number", + "single", + "single-precision", + "float" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "add", + "alias": "add", + "pkg_desc": "compute the sum", + "desc": "computes the sum", + "short_desc": "sum", + "parameters": [ + { + "name": "x", + "desc": "first input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "stdlib_float16_t", + "dtype": "float16" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -10, + 10 + ] + }, + "example_values": [ + 1, + 27, + 0, + 10, + 9, + 8, + 1, + 125, + 20, + 11, + 12, + 3, + 2, + 15, + 16, + 17, + 125, + 19, + 101, + 21 + ] + }, + { + "name": "y", + "desc": "second input value", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "stdlib_float16_t", + "dtype": "float16" + }, + "domain": [ + { + "min": "-infinity", + "max": "infinity" + } + ], + "rand": { + "prng": "random/base/uniform", + "parameters": [ + -10, + 10 + ] + }, + "example_values": [ + 51, + 2, + 10, + 14, + 90, + 88, + 1, + 12, + 120, + 71, + 62, + 31, + 2, + 45, + 26, + 37, + 25, + 59, + 11, + 41 + ] + } + ], + "output_policy": "same", + "returns": { + "desc": "result", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "stdlib_float16_t", + "dtype": "float16" + } + }, + "keywords": [ + "sum", + "addition", + "add" + ], + "extra_keywords": [] + } + } +} diff --git a/lib/node_modules/@stdlib/number/float16/base/add/test/test.js b/lib/node_modules/@stdlib/number/float16/base/add/test/test.js new file mode 100644 index 000000000000..4cd88326bb21 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 tape = require( 'tape' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float16/pinf' ); +var NINF = require( '@stdlib/constants/float16/ninf' ); +var add = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof add, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function adds two numbers', function test( t ) { + t.strictEqual( add( -2.0, 4.0 ), 2.0, 'returns expected value' ); + t.strictEqual( add( 3.0, 0.0 ), 3.0, 'returns expected value' ); + t.strictEqual( add( 0.0, -0.0 ), 0.0, 'returns expected value' ); + t.strictEqual( add( -3.0, -3.0 ), -6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles negative zeros', function test( t ) { + t.strictEqual( isNegativeZero( add( -0.0, -0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( add( -0.0, 0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( add( 0.0, -0.0 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles infinities', function test( t ) { + t.strictEqual( add( PINF, 5.0 ), PINF, 'returns expected value' ); + t.strictEqual( add( 5.0, PINF ), PINF, 'returns expected value' ); + t.strictEqual( add( PINF, PINF ), PINF, 'returns expected value' ); + + t.strictEqual( add( NINF, 5.0 ), NINF, 'returns expected value' ); + t.strictEqual( add( 5.0, NINF ), NINF, 'returns expected value' ); + t.strictEqual( add( NINF, NINF ), NINF, 'returns expected value' ); + + t.strictEqual( isnan( add( NINF, PINF ) ), true, 'returns expected value' ); + t.strictEqual( isnan( add( PINF, NINF ) ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) { + t.strictEqual( isnan( add( NaN, 5.0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( add( NaN, PINF ) ), true, 'returns expected value' ); + t.strictEqual( isnan( add( NaN, NINF ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( add( 5.0, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( add( PINF, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( add( NINF, NaN ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( add( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); +}); From 86f020cc3657e4d54546fa7b03fb9da98daa7ba3 Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Tue, 30 Dec 2025 23:08:19 +0530 Subject: [PATCH 02/17] chore: updating markdown --- .../@stdlib/number/float16/base/add/README.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/README.md b/lib/node_modules/@stdlib/number/float16/base/add/README.md index cd58c1ebf023..928b85599789 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/README.md +++ b/lib/node_modules/@stdlib/number/float16/base/add/README.md @@ -102,22 +102,6 @@ logEachMap( 'x: %0.4f, y: %0.4f => %0.4f', x, y, add ); - - -* * * - -
- -## C APIs - - - -
- -
- - - From 8a1b05174f5a3d689bc055083626fbca4dee8bb8 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 5 Jan 2026 18:14:27 -0800 Subject: [PATCH 12/17] docs: update example Signed-off-by: Athan --- .../@stdlib/number/float16/base/add/examples/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js b/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js index 0be6235403b5..18fbda5b3ff8 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js +++ b/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js @@ -24,11 +24,7 @@ var map = require( '@stdlib/array/base/map' ); var logEachMap = require( '@stdlib/console/log-each-map' ); var add = require( './../lib' ); -// Create an array of random half-precision floating-point numbers: var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); - -// Create an array of random half-precision floating-point numbers: var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); -// Determine the sum of each number: -logEachMap( 'x: %f, y: %f => %f', x, y, add ); +logEachMap( 'add(%f, %f) => %f', x, y, add ); From 8ff5d43593046202b464a0b7fea78c547b0b56ae Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 5 Jan 2026 18:16:50 -0800 Subject: [PATCH 13/17] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/number/float16/base/add/benchmark/benchmark.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js index d3548b3e2422..0e8ac02bb0b0 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.js @@ -26,6 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); var map = require( '@stdlib/array/base/map' ); var naryFunction = require( '@stdlib/utils/nary-function' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var add = require( './../lib' ); @@ -56,7 +57,7 @@ bench( pkg, function benchmark( b ) { b.end(); }); -bench( pkg+'::inline', function benchmark( b ) { +bench( format( '%s::inline', pkg ), function benchmark( b ) { var x; var y; var i; From f136a996c990d2c324f61e440cccd66d3c5cb1a1 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 1 Mar 2026 09:50:38 +0530 Subject: [PATCH 14/17] chore: initial clean up --- .../float16/base/add/benchmark/c/benchmark.c | 2 +- .../number/float16/base/add/manifest.json | 3 - .../number/float16/base/add/package.json | 1 - .../number/float16/base/add/src/addon.c | 89 +------------------ .../number/float16/base/add/test/test.js | 6 +- .../float16/base/add/test/test.native.js | 6 +- 6 files changed, 9 insertions(+), 98 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/c/benchmark.c index bedb78c66c5f..426eb0fc61a2 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/c/benchmark.c @@ -94,8 +94,8 @@ static double rand_double( void ) { static double benchmark( void ) { stdlib_float16_t x[ 100 ]; stdlib_float16_t y[ 100 ]; - double elapsed; stdlib_float16_t z; + double elapsed; double t; int i; diff --git a/lib/node_modules/@stdlib/number/float16/base/add/manifest.json b/lib/node_modules/@stdlib/number/float16/base/add/manifest.json index 2bd64eb88ea9..4fd378b6c478 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/manifest.json +++ b/lib/node_modules/@stdlib/number/float16/base/add/manifest.json @@ -37,8 +37,6 @@ "libpath": [], "dependencies": [ "@stdlib/number/float16/ctor", - "@stdlib/number/float64/base/to-float16", - "@stdlib/number/float16/base/to-float64", "@stdlib/number/float32/base/to-float16", "@stdlib/number/float16/base/to-float32" ] @@ -55,7 +53,6 @@ "libpath": [], "dependencies": [ "@stdlib/number/float16/ctor", - "@stdlib/number/float64/base/to-float16", "@stdlib/number/float32/base/to-float16", "@stdlib/number/float16/base/to-float32" ] diff --git a/lib/node_modules/@stdlib/number/float16/base/add/package.json b/lib/node_modules/@stdlib/number/float16/base/add/package.json index 0cc16f385332..2755c51fe224 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/package.json +++ b/lib/node_modules/@stdlib/number/float16/base/add/package.json @@ -165,7 +165,6 @@ ] } ], - "output_policy": "same", "returns": { "desc": "result", "type": { diff --git a/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c b/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c index b7a4f4347bc0..c28a2945c284 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c +++ b/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c @@ -17,91 +17,6 @@ */ #include "stdlib/number/float16/base/add.h" -#include "stdlib/number/float64/base/to_float16.h" -#include "stdlib/number/float16/base/to_float64.h" -#include "stdlib/number/float16/ctor.h" -#include -#include -#include -#include +#include "stdlib/math/base/napi/binary.h" -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - - // Get callback arguments: - size_t argc = 2; - napi_value argv[ 2 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - // Check whether we were provided the correct number of arguments: - if ( argc < 2 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); - assert( status == napi_ok ); - return NULL; - } - if ( argc > 2 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - napi_valuetype vtype1; - - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double x; - double y; - - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - status = napi_get_value_double( env, argv[ 1 ], &y ); - assert( status == napi_ok ); - - stdlib_float16_t out = stdlib_base_float16_add( stdlib_base_float64_to_float16( x ), stdlib_base_float64_to_float16( y ) ); - - napi_value v; - status = napi_create_double( env, stdlib_base_float16_to_float64( out ), &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* Initializes a Node-API module. -* -* @param env environment under which the function is invoked -* @param exports exports object -* @return main export -*/ -static napi_value init( napi_env env, napi_value exports ) { - napi_value fcn; - napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; -} - -NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) +STDLIB_MATH_BASE_NAPI_MODULE_HH_H( stdlib_base_float16_add ) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/test/test.js b/lib/node_modules/@stdlib/number/float16/base/add/test/test.js index d6640e824405..dc6e8cc4c27e 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/test/test.js +++ b/lib/node_modules/@stdlib/number/float16/base/add/test/test.js @@ -21,9 +21,9 @@ // MODULES // var tape = require( 'tape' ); -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/number/float16/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/number/float16/base/assert/is-positive-zero' ); +var isnan = require( '@stdlib/number/float16/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float16/pinf' ); var NINF = require( '@stdlib/constants/float16/ninf' ); var add = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/number/float16/base/add/test/test.native.js b/lib/node_modules/@stdlib/number/float16/base/add/test/test.native.js index 4890d1fc1e30..721825d6a6b7 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/test/test.native.js +++ b/lib/node_modules/@stdlib/number/float16/base/add/test/test.native.js @@ -22,9 +22,9 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/number/float16/base/assert/is-negative-zero' ); +var isPositiveZero = require( '@stdlib/number/float16/base/assert/is-positive-zero' ); +var isnan = require( '@stdlib/number/float16/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float16/pinf' ); var NINF = require( '@stdlib/constants/float16/ninf' ); var tryRequire = require( '@stdlib/utils/try-require' ); From 8ae3b4842cca166591ddbb56e7e95edfe91dc4ff Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 1 Mar 2026 10:03:21 +0530 Subject: [PATCH 15/17] chore: suppress shadow Function --- lib/node_modules/@stdlib/number/float16/base/add/src/addon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c b/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c index c28a2945c284..1e4c70028d71 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c +++ b/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c @@ -19,4 +19,5 @@ #include "stdlib/number/float16/base/add.h" #include "stdlib/math/base/napi/binary.h" +// cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_HH_H( stdlib_base_float16_add ) From 9c6a5555689e93fa17240247c4304fb7770bdc3a Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 1 Mar 2026 10:17:05 +0530 Subject: [PATCH 16/17] chore: update manifest --- lib/node_modules/@stdlib/number/float16/base/add/manifest.json | 1 + lib/node_modules/@stdlib/number/float16/base/add/src/addon.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/manifest.json b/lib/node_modules/@stdlib/number/float16/base/add/manifest.json index 4fd378b6c478..e24d7f5c7710 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/manifest.json +++ b/lib/node_modules/@stdlib/number/float16/base/add/manifest.json @@ -36,6 +36,7 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/math/base/napi/binary", "@stdlib/number/float16/ctor", "@stdlib/number/float32/base/to-float16", "@stdlib/number/float16/base/to-float32" diff --git a/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c b/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c index 1e4c70028d71..c28a2945c284 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c +++ b/lib/node_modules/@stdlib/number/float16/base/add/src/addon.c @@ -19,5 +19,4 @@ #include "stdlib/number/float16/base/add.h" #include "stdlib/math/base/napi/binary.h" -// cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_HH_H( stdlib_base_float16_add ) From 77e5d049260fdf7f65b54b25ae002e0f1ca77b1f Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 1 Mar 2026 10:22:08 +0530 Subject: [PATCH 17/17] chore: update manifest for bench --- lib/node_modules/@stdlib/number/float16/base/add/manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/number/float16/base/add/manifest.json b/lib/node_modules/@stdlib/number/float16/base/add/manifest.json index e24d7f5c7710..902b0b35755d 100644 --- a/lib/node_modules/@stdlib/number/float16/base/add/manifest.json +++ b/lib/node_modules/@stdlib/number/float16/base/add/manifest.json @@ -54,6 +54,7 @@ "libpath": [], "dependencies": [ "@stdlib/number/float16/ctor", + "@stdlib/number/float64/base/to-float16", "@stdlib/number/float32/base/to-float16", "@stdlib/number/float16/base/to-float32" ]