diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/README.md b/lib/node_modules/@stdlib/number/float16/base/mul/README.md new file mode 100644 index 000000000000..1227ce4d5d9f --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/README.md @@ -0,0 +1,113 @@ + + +# mul + +> Multiply two half-precision floating-point numbers. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var mul = require( '@stdlib/number/float16/base/mul' ); +``` + +#### mul( x, y ) + +Multiplies two half-precision floating-point numbers. + +```javascript +var v = mul( -1.0, 5.0 ); +// returns -5.0 + +v = mul( 2.0, 5.0 ); +// returns 10.0 + +v = mul( 0.0, 5.0 ); +// returns 0.0 + +v = mul( -0.0, 0.0 ); +// returns -0.0 + +v = mul( NaN, NaN ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var mul = require( '@stdlib/number/float16/base/mul' ); + +var x = discreteUniform( 100, -50, 50 ); +var y = discreteUniform( 100, -50, 50 ); + +logEachMap( '%d x %d = %d', x, y, mul ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/mul/benchmark/benchmark.js new file mode 100644 index 000000000000..5bf80538a637 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/benchmark/benchmark.js @@ -0,0 +1,75 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var mul = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = discreteUniform( 100, -100, 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mul( x[ i%x.length ], 5.0 ); + 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(); +}); + +bench( format( '%s::inline', pkg ), function benchmark( b ) { + var x; + var y; + var i; + + x = discreteUniform( 100, -100, 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = x[ i%x.length ] * 5.0; + 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(); +}); diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/base/mul/docs/repl.txt new file mode 100644 index 000000000000..ed04f2b9a1eb --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}( x, y ) + Multiplies 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 ) + -5.0 + > v = {{alias}}( 2.0, 5.0 ) + 10.0 + > v = {{alias}}( 0.0, 5.0 ) + 0.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/mul/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/base/mul/docs/types/index.d.ts new file mode 100644 index 000000000000..92413b3ace89 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/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 + +/** +* Multiplies two half-precision floating-point numbers `x` and `y`. +* +* @param x - first input value +* @param y - second input value +* @returns result +* +* @example +* var v = mul( -1.0, 5.0 ); +* // returns -5.0 +* +* @example +* var v = mul( 2.0, 5.0 ); +* // returns 10.0 +* +* @example +* var v = mul( 0.0, 5.0 ); +* // returns 0.0 +* +* @example +* var v = mul( -0.0, 0.0 ); +* // returns -0.0 +* +* @example +* var v = mul( NaN, NaN ); +* // returns NaN +*/ +declare function mul( x: number, y: number ): number; + + +// EXPORTS // + +export = mul; diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/base/mul/docs/types/test.ts new file mode 100644 index 000000000000..e0a34b50ecc8 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/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 mul = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + mul( 8.0, 8.0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + mul( true, 5.0 ); // $ExpectError + mul( false, 5.0 ); // $ExpectError + mul( null, 5.0 ); // $ExpectError + mul( undefined, 5.0 ); // $ExpectError + mul( '5', 5.0 ); // $ExpectError + mul( [], 5.0 ); // $ExpectError + mul( {}, 5.0 ); // $ExpectError + mul( ( 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... +{ + mul( 5.0, true ); // $ExpectError + mul( 5.0, false ); // $ExpectError + mul( 5.0, null ); // $ExpectError + mul( 5.0, undefined ); // $ExpectError + mul( 5.0, '5' ); // $ExpectError + mul( 5.0, [] ); // $ExpectError + mul( 5.0, {} ); // $ExpectError + mul( 5.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + mul(); // $ExpectError + mul( 5.0 ); // $ExpectError + mul( 5.0, 5.0, 5.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/examples/index.js b/lib/node_modules/@stdlib/number/float16/base/mul/examples/index.js new file mode 100644 index 000000000000..b4a4b364ac6a --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/examples/index.js @@ -0,0 +1,28 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var mul = require( './../lib' ); + +var x = discreteUniform( 100, -50, 50 ); +var y = discreteUniform( 100, -50, 50 ); + +logEachMap( '%d x %d = %d', x, y, mul ); diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/lib/index.js b/lib/node_modules/@stdlib/number/float16/base/mul/lib/index.js new file mode 100644 index 000000000000..e4c4b2382765 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/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'; + +/** +* Multiply two half-precision floating-point numbers. +* +* @module @stdlib/number/float16/base/mul +* +* @example +* var mul = require( '@stdlib/number/float16/base/mul' ); +* +* var v = mul( -1.0, 5.0 ); +* // returns -5.0 +* +* v = mul( 2.0, 5.0 ); +* // returns 10.0 +* +* v = mul( 0.0, 5.0 ); +* // returns 0.0 +* +* v = mul( -0.0, 0.0 ); +* // returns -0.0 +* +* v = mul( NaN, NaN ); +* // returns NaN +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/mul/lib/main.js new file mode 100644 index 000000000000..d1a13deb14d6 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/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 // + +/** +* Multiplies 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 = mul( -1.0, 5.0 ); +* // returns -5.0 +* +* @example +* var v = mul( 2.0, 5.0 ); +* // returns 10.0 +* +* @example +* var v = mul( 0.0, 5.0 ); +* // returns 0.0 +* +* @example +* var v = mul( -0.0, 0.0 ); +* // returns -0.0 +* +* @example +* var v = mul( NaN, NaN ); +* // returns NaN +*/ +function mul( x, y ) { + return float64ToFloat16( float64ToFloat16( x ) * float64ToFloat16( y ) ); +} + + +// EXPORTS // + +module.exports = mul; diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/package.json b/lib/node_modules/@stdlib/number/float16/base/mul/package.json new file mode 100644 index 000000000000..1db52867c611 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/package.json @@ -0,0 +1,183 @@ +{ + "name": "@stdlib/number/float16/base/mul", + "version": "0.0.0", + "description": "Multiply 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", + "product", + "prod", + "multiply", + "multiplication", + "times", + "number", + "half", + "half-precision", + "float" + ], + "__stdlib__": { + "scaffold": { + "$schema": "math/base@v1.0", + "base_alias": "mul", + "alias": "mul", + "pkg_desc": "multiply two half-precision floating-point numbers", + "desc": "multiplies 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": [ + -10, + -5, + -2, + -1, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ] + }, + { + "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": [ + -5, + -4, + -3, + -2, + -1, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14 + ] + } + ], + "returns": { + "desc": "result", + "type": { + "javascript": "number", + "jsdoc": "number", + "c": "stdlib_float16_t", + "dtype": "float16" + } + }, + "keywords": [ + "multiplication", + "multiply", + "product" + ], + "extra_keywords": [] + } + } +} diff --git a/lib/node_modules/@stdlib/number/float16/base/mul/test/test.js b/lib/node_modules/@stdlib/number/float16/base/mul/test/test.js new file mode 100644 index 000000000000..302d3b937da4 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/mul/test/test.js @@ -0,0 +1,83 @@ +/** +* @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 mul = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mul, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function multiplies two numbers', function test( t ) { + t.strictEqual( mul( -2.0, 4.0 ), -8.0, 'returns expected value' ); + t.strictEqual( mul( 3.0, 0.0 ), 0.0, 'returns expected value' ); + t.strictEqual( mul( 0.0, 5.0 ), 0.0, 'returns expected value' ); + t.strictEqual( mul( -3.0, -3.0 ), 9.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles negative zeros', function test( t ) { + t.strictEqual( isPositiveZero( mul( -0.0, -0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( mul( -0.0, 0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isNegativeZero( mul( 0.0, -0.0 ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveZero( mul( 0.0, 0.0 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function handles infinities', function test( t ) { + t.strictEqual( mul( PINF, 5.0 ), PINF, 'returns expected value' ); + t.strictEqual( mul( 5.0, PINF ), PINF, 'returns expected value' ); + t.strictEqual( mul( PINF, PINF ), PINF, 'returns expected value' ); + + t.strictEqual( mul( NINF, 5.0 ), NINF, 'returns expected value' ); + t.strictEqual( mul( 5.0, NINF ), NINF, 'returns expected value' ); + t.strictEqual( mul( NINF, NINF ), PINF, 'returns expected value' ); + + t.strictEqual( mul( NINF, PINF ), NINF, 'returns expected value' ); + t.strictEqual( mul( PINF, NINF ), NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) { + t.strictEqual( isnan( mul( NaN, 5.0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( mul( NaN, PINF ) ), true, 'returns expected value' ); + t.strictEqual( isnan( mul( NaN, NINF ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( mul( 5.0, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( mul( PINF, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( mul( NINF, NaN ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( mul( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); +});