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..cef86ece4636 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/README.md @@ -0,0 +1,115 @@ + + +# add + +> Add two half-precision floating-point numbers. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var add = require( '@stdlib/number/float16/base/add' ); +``` + +#### add( x, y ) + +Adds 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' ); + +var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); +var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); + +logEachMap( 'x: %f, y: %f => %f', x, y, add ); +``` + +
+ + + + + + + + + + + + + + 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..dda75046d81f --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/benchmark/benchmark.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'; + +// 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-nan' ); +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, -100, 100 ), naryFunction( toFloat16, 1 ) ); + y = map( uniform( 100, -100, 100 ), 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..36a301e3c3fd --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x, y ) + Adds two half-precision floating-point numbers `x` and `y`. + + Parameters + ---------- + x: number + First input value. + + y: number + Second input value. + + Returns + ------- + out: number + Result. + + 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..1c7821fa93a8 --- /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) 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 + +/** +* Adds two half-precision floating-point numbers `x` and `y`. +* +* @param x - first input value +* @param y - second input value +* @returns result +* +* @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..6055e2d26d68 --- /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) 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 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..8ec3dec0dc2a --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/examples/index.js @@ -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 uniform = require( '@stdlib/random/array/uniform' ); +var map = require( '@stdlib/array/base/map' ); +var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var add = require( './../lib' ); + +var x = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); +var y = map( uniform( 100, -50.0, 50.0 ), toFloat16 ); + +logEachMap( 'x: %f, y: %f => %f', 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..e059c212c16f --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/lib/index.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'; + +/** +* Add 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..ae3d5932e0c4 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/lib/main.js @@ -0,0 +1,62 @@ +/** +* @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 float64ToFloat16 = require( '@stdlib/number/float64/base/to-float16' ); + + +// MAIN // + +/** +* Adds two half-precision floating-point numbers `x` and `y`. +* +* @param {number} x - first input value +* @param {number} y - second input value +* @returns {number} result +* +* @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..1a3caf04547e --- /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": "Add 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", + "plus", + "number", + "float", + "half", + "half-precision" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "add", + "alias": "add", + "pkg_desc": "addition of two half-precision floating-point numbers", + "desc": "addition of two half-precision floating-point numbers", + "short_desc": "", + "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": [ + "addition", + "add", + "sum" + ], + "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..c260405fd55c --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/add/test/test.js @@ -0,0 +1,83 @@ +/** +* @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 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.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(); +});