From 3477c5ddca2f13995029cd19ee59668d6910248f Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sat, 10 Jan 2026 17:40:31 +0530 Subject: [PATCH 1/2] feat: add initial setup --- .../base/assert/is-same-value/README.md | 125 ++++++++++++++++++ .../is-same-value/benchmark/benchmark.js | 60 +++++++++ .../base/assert/is-same-value/docs/repl.txt | 36 +++++ .../is-same-value/docs/types/index.d.ts | 61 +++++++++ .../assert/is-same-value/docs/types/test.ts | 58 ++++++++ .../assert/is-same-value/examples/index.js | 34 +++++ .../base/assert/is-same-value/lib/index.js | 50 +++++++ .../base/assert/is-same-value/lib/main.js | 66 +++++++++ .../base/assert/is-same-value/package.json | 76 +++++++++++ .../base/assert/is-same-value/test/test.js | 76 +++++++++++ 10 files changed, 642 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/README.md create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/examples/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/main.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/package.json create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/test/test.js diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/README.md b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/README.md new file mode 100644 index 000000000000..401b43e2ac12 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/README.md @@ -0,0 +1,125 @@ + + +# isSameValue + +> Test if two half-precision floating-point numbers are the same value. + +
+ +## Usage + +```javascript +var isSameValue = require( '@stdlib/number/float16/base/assert/is-same-value' ); +``` + +#### isSameValue( a, b ) + +Tests if two half-precision floating-point numbers `a` and `b` are the same value. + +```javascript +var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); + +var bool = isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) ); +// returns true + +bool = isSameValue( toFloat16( 5.0 ), toFloat16( 3.0 ) ); +// returns false +``` + +In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value. + + + +```javascript +var bool = ( 0.0 === -0.0 ); +// returns true + +bool = isSameValue( 0.0, -0.0 ); +// returns false + +bool = isSameValue( -0.0, -0.0 ); +// returns true + +bool = ( NaN === NaN ); +// returns false + +bool = isSameValue( NaN, NaN ); +// returns true +``` + +
+ + + +
+ +## Notes + +- The function implements the [SameValue Algorithm][ecma-262-same-value-algorithm] as specified in ECMAScript 5. + +
+ + + +
+ +## Examples + + + +```javascript +var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +var isSameValue = require( '@stdlib/number/float16/base/assert/is-same-value' ); + +var bool = isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) ); +// returns true + +bool = isSameValue( toFloat16( 0.0 ), toFloat16( 0.0 ) ); +// returns true + +bool = isSameValue( toFloat16( -0.0 ), toFloat16( 0.0 ) ); +// returns false + +bool = isSameValue( toFloat16( NaN ), toFloat16( NaN ) ); +// returns true +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js new file mode 100644 index 000000000000..b96a7928d733 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js @@ -0,0 +1,60 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isSameValue = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var bool; + var v; + var i; + + values = [ + 5.0, + 3.14, + NaN, + -0.0, + 0.0, + -1.0 + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ]; + bool = isSameValue( v, v ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/repl.txt new file mode 100644 index 000000000000..8134527b5ee9 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( a, b ) + Tests if two half-precision floating-point numbers are the same value. + + The function differs from the `===` operator in that the function treats + `-0` and `+0` as distinct and `NaNs` as the same. + + Parameters + ---------- + a: number + First input value. + + b: number + Second input value. + + Returns + ------- + bool: boolean + Boolean indicating whether two half-precision floating-point numbers + are the same value. + + Examples + -------- + > var v1 = {{alias:@stdlib/number/float64/base/to-float16}}( -0.0 ); + > var bool = {{alias}}( v1, v1 ) + true + > var v2 = {{alias:@stdlib/number/float64/base/to-float16}}( 0.0 ); + > bool = {{alias}}( v1, v2 ) + false + > v1 = {{alias:@stdlib/number/float64/base/to-float16}}( NaN ); + > bool = {{alias}}( v1, v1 ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/index.d.ts new file mode 100644 index 000000000000..1edf6e92e6e8 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/index.d.ts @@ -0,0 +1,61 @@ +/* +* @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 + +/** +* Tests if two half-precision floating-point numbers are the same value. +* +* ## Notes +* +* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. +* +* @param a - first input value +* @param b - second input value +* @returns boolean indicating whether two half-precision floating-point numbers are the same value +* +* @example +* var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +* +* var bool = isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) ); +* // returns true +* +* @example +* var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +* +* var bool = isSameValue( toFloat16( -0.0 ), toFloat16( -0.0 ) ); +* // returns true +* +* @example +* var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +* +* var bool = isSameValue( toFloat16( -0.0 ), toFloat16( 0.0 ) ); +* // returns false +* +* @example +* var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +* +* var bool = isSameValue( toFloat16( NaN ), toFloat16( NaN ) ); +* // returns true +*/ +declare function isSameValue( a: number, b: number ): boolean; + + +// EXPORTS // + +export = isSameValue; diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/docs/types/test.ts new file mode 100644 index 000000000000..6a0e77bf65a3 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/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 isSameValue = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isSameValue( 3.14, 3.14 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is not provided a first argument which is a number... +{ + isSameValue( '5', 3.14 ); // $ExpectError + isSameValue( true, 3.14 ); // $ExpectError + isSameValue( false, 3.14 ); // $ExpectError + isSameValue( null, 3.14 ); // $ExpectError + isSameValue( void 0, 3.14 ); // $ExpectError + isSameValue( [], 3.14 ); // $ExpectError + isSameValue( {}, 3.14 ); // $ExpectError + isSameValue( ( x: number ): number => x, 3.14 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a second argument which is a number... +{ + isSameValue( 3.14, '5' ); // $ExpectError + isSameValue( 3.14, true ); // $ExpectError + isSameValue( 3.14, false ); // $ExpectError + isSameValue( 3.14, null ); // $ExpectError + isSameValue( 3.14, void 0 ); // $ExpectError + isSameValue( 3.14, [] ); // $ExpectError + isSameValue( 3.14, {} ); // $ExpectError + isSameValue( 3.14, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isSameValue(); // $ExpectError + isSameValue( 3.14 ); // $ExpectError + isSameValue( 3.14, 3.14, 3.14 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/examples/index.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/examples/index.js new file mode 100644 index 000000000000..1f61cdc7f3c4 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 isSameValue = require( './../lib' ); + +console.log( isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) ) ); +// => true + +console.log( isSameValue( toFloat16( 0.0 ), toFloat16( 0.0 ) ) ); +// => true + +console.log( isSameValue( toFloat16( -0.0 ), toFloat16( 0.0 ) ) ); +// => false + +console.log( isSameValue( toFloat16( NaN ), toFloat16( NaN ) ) ); +// => true diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/index.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/index.js new file mode 100644 index 000000000000..d8cae7a0b5f0 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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'; + +/** +* Test if two half-precision floating-point numbers are the same value. +* +* @module @stdlib/number/float16/base/assert/is-same-value +* +* @example +* var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); +* var isSameValue = require( '@stdlib/number/float16/base/assert/is-same-value' ); +* +* var bool = isSameValue( toFloat16( 3.14 ), toFloat16( 3.14 ) ); +* // returns true +* +* bool = isSameValue( toFloat16( -0.0 ), toFloat16( -0.0 ) ); +* // returns true +* +* bool = isSameValue( toFloat16( -0.0 ), toFloat16( 0.0 ) ); +* // returns false +* +* bool = isSameValue( toFloat16( NaN ), toFloat16( NaN ) ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/main.js new file mode 100644 index 000000000000..146e4f99d6f3 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/lib/main.js @@ -0,0 +1,66 @@ +/** +* @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'; + +// MAIN // + +/** +* Tests if two half-precision floating-point numbers are the same value. +* +* ## Notes +* +* - The function implements the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. +* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. +* +* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 +* +* @param {number} a - first input value +* @param {number} b - second input value +* @returns {boolean} boolean indicating whether two half-precision floating-point numbers are the same value +* +* @example +* var bool = isSameValue( 3.14, 3.14 ); +* // returns true +* +* @example +* var bool = isSameValue( -0.0, -0.0 ); +* // returns true +* +* @example +* var bool = isSameValue( -0.0, 0.0 ); +* // returns false +* +* @example +* var bool = isSameValue( NaN, NaN ); +* // returns true +*/ +function isSameValue( a, b ) { + if ( a === b ) { + if ( a === 0.0 ) { + return 1.0 / a === 1.0 / b; // handles +-0 + } + return true; + } + return ( a !== a && b !== b ); // handles NaNs +} + + +// EXPORTS // + +module.exports = isSameValue; diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/package.json b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/package.json new file mode 100644 index 000000000000..06565cb853fd --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/number/float16/base/assert/is-same-value", + "version": "0.0.0", + "description": "Test if two half-precision floating-point numbers are the same value.", + "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", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "equal", + "same", + "strict", + "is", + "issame", + "issamevalue", + "isequal", + "isstrictequal", + "type", + "check", + "valid", + "validate", + "test", + "float", + "half-precision" + ] +} diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/test/test.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/test/test.js new file mode 100644 index 000000000000..340b98eda7ae --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/test/test.js @@ -0,0 +1,76 @@ +/** +* @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 isSameValue = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isSameValue, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided two half-precision floating-point numbers which are the same value', function test( t ) { + var values; + var i; + + values = [ + 5.0, + 3.14, + -3.14, + 0.0, + -0.0, + NaN + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isSameValue( values[ i ], values[ i ] ), true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided two half-precision floating-point numbers which are the same value', function test( t ) { + var a; + var b; + var i; + + a = [ + 5.0, + 3.14, + -3.14, + 0.0, + -0.0 + ]; + b = [ + -5.0, + -3.14, + 3.14, + -0.0, + 0.0 + ]; + for ( i = 0; i < a.length; i++ ) { + t.strictEqual( isSameValue( a[ i ], b[ i ] ), false, 'returns expected value when provided '+a[ i ]+' and '+b[ i ] ); + } + t.end(); +}); From ba153e1b5ebff4bcd1219c10cb37085c2ebaa524 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sat, 10 Jan 2026 17:45:05 +0530 Subject: [PATCH 2/2] chore: remove trailing whitespace --- .../float16/base/assert/is-same-value/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js index b96a7928d733..d82f3a003ebe 100644 --- a/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-same-value/benchmark/benchmark.js @@ -35,7 +35,7 @@ bench( pkg, function benchmark( b ) { var i; values = [ - 5.0, + 5.0, 3.14, NaN, -0.0,