diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/README.md b/lib/node_modules/@stdlib/number/float16/base/sub/README.md new file mode 100644 index 000000000000..02fb5c84b9f0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/README.md @@ -0,0 +1,115 @@ + + +# sub + +> Subtract two half-precision floating-point numbers. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var sub = require( '@stdlib/number/float16/base/sub' ); +``` + +#### sub( x, y ) + +Subtracts two half-precision floating-point numbers. + +```javascript +var v = sub( -1.0, 5.0 ); +// returns -6.0 + +v = sub( 2.0, 5.0 ); +// returns -3.0 + +v = sub( 0.0, 5.0 ); +// returns -5.0 + +v = sub( -0.0, 0.0 ); +// returns -0.0 + +v = sub( 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 sub = require( '@stdlib/number/float16/base/sub' ); + +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, sub ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/sub/benchmark/benchmark.js new file mode 100644 index 000000000000..b43dce23a2e1 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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 sub = 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 = sub( 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/sub/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/base/sub/docs/repl.txt new file mode 100644 index 000000000000..bcc74b299dca --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x, y ) + Subtracts two half-precision floating-point numbers `x` and `y`. + + Parameters + ---------- + x: number + First input value. + + y: number + Second input value. + + Returns + ------- + z: number + Result. + + Examples + -------- + > var v = {{alias}}( -1.0, 5.0 ) + -6.0 + > v = {{alias}}( 2.0, 5.0 ) + -3.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/sub/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/base/sub/docs/types/index.d.ts new file mode 100644 index 000000000000..be083b2ad47a --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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 + +/** +* Subtracts two half-precision floating-point numbers `x` and `y`. +* +* @param x - first input value +* @param y - second input value +* @returns result +* +* @example +* var v = sub( -1.0, 5.0 ); +* // returns -6.0 +* +* @example +* var v = sub( 2.0, 5.0 ); +* // returns -3.0 +* +* @example +* var v = sub( 0.0, 5.0 ); +* // returns -5.0 +* +* @example +* var v = sub( -0.0, 0.0 ); +* // returns -0.0 +* +* @example +* var v = sub( NaN, NaN ); +* // returns NaN +*/ +declare function sub( x: number, y: number ): number; + + +// EXPORTS // + +export = sub; diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/base/sub/docs/types/test.ts new file mode 100644 index 000000000000..15ecf9453ca7 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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 sub = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + sub( 8.0, 8.0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + sub( true, 5.0 ); // $ExpectError + sub( false, 5.0 ); // $ExpectError + sub( null, 5.0 ); // $ExpectError + sub( undefined, 5.0 ); // $ExpectError + sub( '5', 5.0 ); // $ExpectError + sub( [], 5.0 ); // $ExpectError + sub( {}, 5.0 ); // $ExpectError + sub( ( 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... +{ + sub( 5.0, true ); // $ExpectError + sub( 5.0, false ); // $ExpectError + sub( 5.0, null ); // $ExpectError + sub( 5.0, undefined ); // $ExpectError + sub( 5.0, '5' ); // $ExpectError + sub( 5.0, [] ); // $ExpectError + sub( 5.0, {} ); // $ExpectError + sub( 5.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + sub(); // $ExpectError + sub( 5.0 ); // $ExpectError + sub( 5.0, 5.0, 5.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/examples/index.js b/lib/node_modules/@stdlib/number/float16/base/sub/examples/index.js new file mode 100644 index 000000000000..b1d4e886a765 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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 sub = 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, sub ); diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/lib/index.js b/lib/node_modules/@stdlib/number/float16/base/sub/lib/index.js new file mode 100644 index 000000000000..04cf4648a604 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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'; + +/** +* Subtract two half-precision floating-point numbers. +* +* @module @stdlib/number/float16/base/sub +* +* @example +* var sub = require( '@stdlib/number/float16/base/sub' ); +* +* var v = sub( -1.0, 5.0 ); +* // returns -6.0 +* +* v = sub( 2.0, 5.0 ); +* // returns -3.0 +* +* v = sub( 0.0, 5.0 ); +* // returns -5.0 +* +* v = sub( -0.0, 0.0 ); +* // returns -0.0 +* +* v = sub( NaN, NaN ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/sub/lib/main.js new file mode 100644 index 000000000000..1f67e8396a75 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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 // + +/** +* Subtracts 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 = sub( -1.0, 5.0 ); +* // returns -6.0 +* +* @example +* var v = sub( 2.0, 5.0 ); +* // returns -3.0 +* +* @example +* var v = sub( 0.0, 5.0 ); +* // returns -5.0 +* +* @example +* var v = sub( -0.0, 0.0 ); +* // returns -0.0 +* +* @example +* var v = sub( NaN, NaN ); +* // returns NaN +*/ +function sub( x, y ) { + return float64ToFloat16( float64ToFloat16( x ) - float64ToFloat16( y ) ); +} + + +// EXPORTS // + +module.exports = sub; diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/package.json b/lib/node_modules/@stdlib/number/float16/base/sub/package.json new file mode 100644 index 000000000000..742258e5c5e0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/package.json @@ -0,0 +1,183 @@ +{ + "name": "@stdlib/number/float16/base/sub", + "version": "0.0.0", + "description": "Subtract 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", + "difference", + "sub", + "subtraction", + "minus", + "number", + "float", + "half", + "half-precision" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "sub", + "alias": "sub", + "pkg_desc": "subtraction of two half-precision floating-point numbers", + "desc": "subtraction 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": [ + "subtraction", + "subtract", + "difference" + ], + "extra_keywords": [] + } + } +} diff --git a/lib/node_modules/@stdlib/number/float16/base/sub/test/test.js b/lib/node_modules/@stdlib/number/float16/base/sub/test/test.js new file mode 100644 index 000000000000..340a4a612600 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/sub/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 sub = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sub, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function subtracts two numbers', function test( t ) { + t.strictEqual( sub( -2.0, 4.0 ), -6.0, 'returns expected value' ); + t.strictEqual( sub( 3.0, 0.0 ), 3.0, 'returns expected value' ); + t.strictEqual( sub( 0.0, -0.0 ), 0.0, 'returns expected value' ); + t.strictEqual( sub( -3.0, -3.0 ), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles negative zeros', function test( t ) { + t.strictEqual( isPositiveZero( sub( -0.0, -0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( sub( -0.0, 0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( sub( 0.0, -0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( sub( 0.0, 0.0 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles infinities', function test( t ) { + t.strictEqual( sub( PINF, 5.0 ), PINF, 'returns expected value' ); + t.strictEqual( sub( 5.0, PINF ), NINF, 'returns expected value' ); + t.strictEqual( isnan( sub( PINF, PINF ) ), true, 'returns expected value' ); + + t.strictEqual( sub( NINF, 5.0 ), NINF, 'returns expected value' ); + t.strictEqual( sub( 5.0, NINF ), PINF, 'returns expected value' ); + t.strictEqual( isnan( sub( NINF, NINF ) ), true, 'returns expected value' ); + + t.strictEqual( sub( NINF, PINF ), NINF, 'returns expected value' ); + t.strictEqual( sub( PINF, NINF ), PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) { + t.strictEqual( isnan( sub( NaN, 5.0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( sub( NaN, PINF ) ), true, 'returns expected value' ); + t.strictEqual( isnan( sub( NaN, NINF ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( sub( 5.0, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( sub( PINF, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( sub( NINF, NaN ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( sub( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); +});