From 291b426cf243714c0dbc7390fa4c9b22fbdf810f Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sat, 10 Jan 2026 10:27:23 +0530 Subject: [PATCH 1/5] feat: add number/float16/base/assert/is-almost-same-value --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../assert/is-almost-same-value/README.md | 117 ++++++++++++++++++ .../benchmark/benchmark.js | 60 +++++++++ .../assert/is-almost-same-value/docs/repl.txt | 42 +++++++ .../docs/types/index.d.ts | 62 ++++++++++ .../is-almost-same-value/docs/types/test.ts | 71 +++++++++++ .../is-almost-same-value/examples/index.js | 50 ++++++++ .../assert/is-almost-same-value/lib/index.js | 59 +++++++++ .../assert/is-almost-same-value/lib/main.js | 97 +++++++++++++++ .../assert/is-almost-same-value/package.json | 75 +++++++++++ .../assert/is-almost-same-value/test/test.js | 89 +++++++++++++ 10 files changed, 722 insertions(+) create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/examples/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/index.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/package.json create mode 100644 lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md new file mode 100644 index 000000000000..190f739f9414 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md @@ -0,0 +1,117 @@ + + +# isAlmostSameValue + +> Test if two half-precision floating-point numbers are approximately the same value within a specified number of ULPs (units in the last place). + +
+ +## Usage + +```javascript +var isAlmostSameValue = require( '@stdlib/number/float16/base/assert/is-almost-same-value' ); +``` + +#### isAlmostSameValue( a, b, maxULP ) + +Tests if two half-precision floating-point numbers are approximately the same value within a specified number of ULPs (units in the last place). + +```javascript +var EPS = require( '@stdlib/constants/float16/eps' ); + +var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); +// returns true + +bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); +// returns false +``` + +The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. + +```javascript +var bool = isAlmostSameValue( 0.0, -0.0, 0 ); +// returns false + +bool = isAlmostSameValue( NaN, NaN, 1 ); +// returns true +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var EPS = require( '@stdlib/constants/float16/eps' ); +var isAlmostSameValue = require( '@stdlib/number/float16/base/assert/is-almost-same-value' ); + +var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); +// returns true + +bool = isAlmostSameValue( 1.0+EPS, 1.0, 1 ); +// returns true + +bool = isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); +// returns false + +bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); +// returns false + +bool = isAlmostSameValue( -0.0, 0.0, 0 ); +// returns false + +bool = isAlmostSameValue( 1.0, NaN, 1 ); +// returns false + +bool = isAlmostSameValue( NaN, NaN, 1 ); +// returns true +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/benchmark/benchmark.js new file mode 100644 index 000000000000..d95eb78cd068 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-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 isAlmostSameValue = 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 = isAlmostSameValue( v, v, 1 ); + 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-almost-same-value/docs/repl.txt b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/repl.txt new file mode 100644 index 000000000000..5d9b4d6389dd --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/repl.txt @@ -0,0 +1,42 @@ +{{alias}}( a, b, maxULP ) + Tests if two half-precision floating-point numbers are approximately the + same value within a specified number of ULPs (units in the last place). + + 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. + + maxULP: number + Maximum allowed ULP difference. + + Returns + ------- + bool: boolean + Boolean indicating whether two half-precision floating-point numbers + are approximately the same value within a specified number of ULPs. + + Examples + -------- + > var bool = {{alias}}( 1, 1+{{alias:@stdlib/constants/float16/eps}}, 1 ) + true + > bool = {{alias}}( 1+{{alias:@stdlib/constants/float16/eps}}, 1, 1 ) + true + > bool = {{alias}}( 1, 1+{{alias:@stdlib/constants/float16/eps}}*2, 1 ) + false + > bool = {{alias}}( 0.0, -0.0, 0 ) + false + > bool = {{alias}}( NaN, 1.0, 1 ) + false + > bool = {{alias}}( NaN, NaN, 0 ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/index.d.ts new file mode 100644 index 000000000000..dc8efb0ace21 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/** +* Tests if two half-precision floating-point numbers are approximately the same value within a specified number of ULPs (units in the last place). +* +* ## 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 +* @param maxULP - maximum allowed ULP difference +* @returns boolean indicating whether two half-precision floating-point numbers are approximately the same value within a specified number of ULPs +* +* @example +* var EPS = require( '@stdlib/constants/float16/eps' ); +* +* var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); +* // returns true +* +* bool = isAlmostSameValue( 1.0+EPS, 1.0, 1 ); +* // returns true +* +* bool = isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); +* // returns false +* +* bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); +* // returns false +* +* bool = isAlmostSameValue( 0.0, -0.0, 0 ); +* // returns false +* +* bool = isAlmostSameValue( 1.0, NaN, 1 ); +* // returns false +* +* bool = isAlmostSameValue( NaN, NaN, 1 ); +* // returns true +*/ +declare function isAlmostSameValue( a: number, b: number, maxULP: number ): boolean; + + +// EXPORTS // + +export = isAlmostSameValue; diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/test.ts b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/test.ts new file mode 100644 index 000000000000..db8a6fdbc59c --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/docs/types/test.ts @@ -0,0 +1,71 @@ +/* +* @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 isAlmostSameValue = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isAlmostSameValue( 3.14, 3.14, 1 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is not provided a first argument which is a number... +{ + isAlmostSameValue( '5', 3.14, 1 ); // $ExpectError + isAlmostSameValue( true, 3.14, 1 ); // $ExpectError + isAlmostSameValue( false, 3.14, 1 ); // $ExpectError + isAlmostSameValue( null, 3.14, 1 ); // $ExpectError + isAlmostSameValue( void 0, 3.14, 1 ); // $ExpectError + isAlmostSameValue( [], 3.14, 1 ); // $ExpectError + isAlmostSameValue( {}, 3.14, 1 ); // $ExpectError + isAlmostSameValue( ( x: number ): number => x, 3.14, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a second argument which is a number... +{ + isAlmostSameValue( 3.14, '5', 1 ); // $ExpectError + isAlmostSameValue( 3.14, true, 1 ); // $ExpectError + isAlmostSameValue( 3.14, false, 1 ); // $ExpectError + isAlmostSameValue( 3.14, null, 1 ); // $ExpectError + isAlmostSameValue( 3.14, void 0, 1 ); // $ExpectError + isAlmostSameValue( 3.14, [], 1 ); // $ExpectError + isAlmostSameValue( 3.14, {}, 1 ); // $ExpectError + isAlmostSameValue( 3.14, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a third argument which is a number... +{ + isAlmostSameValue( 3.14, 3.14, '5' ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, true ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, false ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, null ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, void 0 ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, [] ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, {} ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isAlmostSameValue(); // $ExpectError + isAlmostSameValue( 3.14 ); // $ExpectError + isAlmostSameValue( 3.14, 3.14 ); // $ExpectError + isAlmostSameValue( 3.14, 3.14, 1, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/examples/index.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/examples/index.js new file mode 100644 index 000000000000..fdfa1773ee21 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/examples/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'; + +var EPS = require( '@stdlib/constants/float16/eps' ); +var isAlmostSameValue = require( './../lib' ); + +var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); +console.log( bool ); +// => true + +bool = isAlmostSameValue( 1.0+EPS, 1.0, 1 ); +console.log( bool ); +// => true + +bool = isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); +console.log( bool ); +// => false + +bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); +console.log( bool ); +// => false + +bool = isAlmostSameValue( -0.0, 0.0, 0 ); +console.log( bool ); +// => false + +bool = isAlmostSameValue( 1.0, NaN, 1 ); +console.log( bool ); +// => false + +bool = isAlmostSameValue( NaN, NaN, 1 ); +console.log( bool ); +// => true diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/index.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/index.js new file mode 100644 index 000000000000..1cf7df840859 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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 approximately the same value within a specified number of ULPs (units in the last place). +* +* @module @stdlib/number/float16/base/assert/is-almost-same-value +* +* @example +* var EPS = require( '@stdlib/constants/float16/eps' ); +* var isAlmostSameValue = require( '@stdlib/number/float16/base/assert/is-almost-same-value' ); +* +* var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); +* // returns true +* +* bool = isAlmostSameValue( 1.0+EPS, 1.0, 1 ); +* // returns true +* +* bool = isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); +* // returns false +* +* bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); +* // returns false +* +* bool = isAlmostSameValue( 0.0, -0.0, 0 ); +* // returns false +* +* bool = isAlmostSameValue( 1.0, NaN, 1 ); +* // returns false +* +* bool = isAlmostSameValue( NaN, NaN, 1 ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js new file mode 100644 index 000000000000..a7605ed466cc --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js @@ -0,0 +1,97 @@ +/** +* @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 f16 = require( '@stdlib/number/float64/base/to-float16' ); +var ulpdiff = require( '@stdlib/number/float16/base/ulp-difference' ); +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' ); + + +// MAIN // + +/** +* Tests if two half-precision floating-point numbers are approximately the same value within a specified number of ULPs (units in the last place). +* +* ## Notes +* +* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. +* +* @param {number} a - first input value +* @param {number} b - second input value +* @param {number} maxULP - maximum allowed ULP difference +* @returns {boolean} boolean indicating whether two half-precision floating-point numbers are approximately the same value within a specified number of ULPs +* +* @example +* var EPS = require( '@stdlib/constants/float16/eps' ); +* +* var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); +* // returns true +* +* bool = isAlmostSameValue( 1.0+EPS, 1.0, 1 ); +* // returns true +* +* bool = isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); +* // returns false +* +* bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); +* // returns false +* +* bool = isAlmostSameValue( 0.0, -0.0, 0 ); +* // returns false +* +* bool = isAlmostSameValue( 1.0, NaN, 1 ); +* // returns false +* +* bool = isAlmostSameValue( NaN, NaN, 1 ); +* // returns true +*/ +function isAlmostSameValue( a, b, maxULP ) { + var af; + var bf; + + af = f16( a ); + bf = f16( b ); + + // Handle NaN values (NaN === NaN in SameValue): + if ( isnan( af ) && isnan( bf ) ) { + return true; + } + // Handle signed zeros (-0 !== +0 in SameValue): + if ( isPositiveZero( af ) && isNegativeZero( bf ) ) { + return false; + } + if ( isNegativeZero( af ) && isPositiveZero( bf ) ) { + return false; + } + // Check if exactly the same: + if ( af === bf ) { + return true; + } + // Check ULP difference: + return ulpdiff( af, bf ) <= maxULP; +} + + +// EXPORTS // + +module.exports = isAlmostSameValue; diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/package.json b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/package.json new file mode 100644 index 000000000000..79615123c663 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/number/float16/base/assert/is-almost-same-value", + "version": "0.0.0", + "description": "Test if two half-precision floating-point numbers are approximately the same value within a specified number of ULPs (units in the last place).", + "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", + "isequal", + "isalmostsamevalue", + "type", + "check", + "valid", + "validate", + "test", + "float", + "half-precision" + ] +} diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js new file mode 100644 index 000000000000..4a1eaa25a014 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js @@ -0,0 +1,89 @@ +/** +* @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 EPS = require( '@stdlib/constants/float16/eps' ); +var isAlmostSameValue = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isAlmostSameValue, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided `NaN` as both input values irrespective of the specified number of ULPs', function test( t ) { + t.strictEqual( isAlmostSameValue( NaN, NaN, 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( NaN, NaN, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( NaN, NaN, 10 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if only one input value is `NaN`', function test( t ) { + t.strictEqual( isAlmostSameValue( NaN, 3.14, 0 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 3.14, NaN, 0 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( NaN, 3.14, 1 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 3.14, NaN, 1 ), false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `true` if provided two half-precision floating-point numbers which are the same value irrespective of the specified number of ULPs', function test( t ) { + var values; + var i; + + values = [ + 5.0, + 3.14, + -3.14, + 0.0, + -0.0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isAlmostSameValue( values[ i ], values[ i ], 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( values[ i ], values[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns `true` if provided two half-precision floating-point numbers which are approximately the same value within a specified number of ULPs', function test( t ) { + t.strictEqual( isAlmostSameValue( 1.0, 1.0+EPS, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 1.0+EPS, 1.0, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 1.0, 1.0+EPS+EPS, 2 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if provided two half-precision floating-point numbers which are not approximately the same value within a specified number of ULPs', function test( t ) { + t.strictEqual( isAlmostSameValue( 1.0, 1.0+EPS, 0 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 1.0+EPS, 1.0, 0 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ), false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if signed zeros are provided as input values irrespective of the specified number of ULPs', function test( t ) { + t.strictEqual( isAlmostSameValue( 0.0, -0.0, 0 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( -0.0, 0.0, 0 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 0.0, -0.0, 1 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( -0.0, 0.0, 1 ), false, 'returns expected value' ); + t.end(); +}); From 9f477b43ceb1d5d1a43cf949e095cf01d3ece75a Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sat, 10 Jan 2026 10:40:06 +0530 Subject: [PATCH 2/5] chore: retrigger CI --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- From 120e4108b391b9dded27c16254603d6cec204a3d Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sat, 10 Jan 2026 12:06:50 +0530 Subject: [PATCH 3/5] chore(build): fix requested changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../assert/is-almost-same-value/lib/main.js | 18 ++++++------------ .../assert/is-almost-same-value/test/test.js | 6 +++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js index a7605ed466cc..320ffb49c525 100644 --- a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js @@ -22,9 +22,6 @@ var f16 = require( '@stdlib/number/float64/base/to-float16' ); var ulpdiff = require( '@stdlib/number/float16/base/ulp-difference' ); -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' ); // MAIN // @@ -72,18 +69,15 @@ function isAlmostSameValue( a, b, maxULP ) { af = f16( a ); bf = f16( b ); - // Handle NaN values (NaN === NaN in SameValue): - if ( isnan( af ) && isnan( bf ) ) { + // Check for NaN (NaN is considered equal to NaN in SameValue): + if ( af !== af && bf !== bf ) { return true; } - // Handle signed zeros (-0 !== +0 in SameValue): - if ( isPositiveZero( af ) && isNegativeZero( bf ) ) { - return false; + // Only distinguish signed zeros when maxULP is 0: + if ( maxULP === 0 && af === 0.0 && bf === 0.0 ) { + return ( 1.0 / af === 1.0 / bf ); } - if ( isNegativeZero( af ) && isPositiveZero( bf ) ) { - return false; - } - // Check if exactly the same: + // Check if exactly equal: if ( af === bf ) { return true; } diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js index 4a1eaa25a014..1a559133e60d 100644 --- a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/test/test.js @@ -80,10 +80,10 @@ tape( 'the function returns `false` if provided two half-precision floating-poin t.end(); }); -tape( 'the function returns `false` if signed zeros are provided as input values irrespective of the specified number of ULPs', function test( t ) { +tape( 'the function distinguishes between signed zeros when the specified number of ULPs is zero', function test( t ) { t.strictEqual( isAlmostSameValue( 0.0, -0.0, 0 ), false, 'returns expected value' ); t.strictEqual( isAlmostSameValue( -0.0, 0.0, 0 ), false, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( 0.0, -0.0, 1 ), false, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( -0.0, 0.0, 1 ), false, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( 0.0, -0.0, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( -0.0, 0.0, 1 ), true, 'returns expected value' ); t.end(); }); From c5dfd8d210431452ab489c94ef6beebf476805b7 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sat, 10 Jan 2026 13:50:56 +0530 Subject: [PATCH 4/5] chore(build): fix requested changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../float16/base/assert/is-almost-same-value/lib/main.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js index 320ffb49c525..e8e7e1ce8efa 100644 --- a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/lib/main.js @@ -20,6 +20,7 @@ // MODULES // +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var f16 = require( '@stdlib/number/float64/base/to-float16' ); var ulpdiff = require( '@stdlib/number/float16/base/ulp-difference' ); @@ -31,7 +32,10 @@ var ulpdiff = require( '@stdlib/number/float16/base/ulp-difference' ); * * ## Notes * -* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. +* - 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 @@ -70,7 +74,7 @@ function isAlmostSameValue( a, b, maxULP ) { bf = f16( b ); // Check for NaN (NaN is considered equal to NaN in SameValue): - if ( af !== af && bf !== bf ) { + if ( isnan( af ) && isnan( bf ) ) { return true; } // Only distinguish signed zeros when maxULP is 0: From 8d1997da8cd19d7647be5b449d4e01475be12965 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sat, 10 Jan 2026 13:57:44 +0530 Subject: [PATCH 5/5] chore(build): fixed readme --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../assert/is-almost-same-value/README.md | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md index 190f739f9414..e528c48a8240 100644 --- a/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md +++ b/lib/node_modules/@stdlib/number/float16/base/assert/is-almost-same-value/README.md @@ -44,14 +44,20 @@ bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); // returns false ``` -The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. +In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value. ```javascript -var bool = isAlmostSameValue( 0.0, -0.0, 0 ); +var bool = isAlmostSameValue( NaN, 1.0, 1 ); +// returns false + +bool = isAlmostSameValue( 1.0, NaN, 1 ); // returns false bool = isAlmostSameValue( NaN, NaN, 1 ); // returns true + +bool = isAlmostSameValue( 0.0, -0.0, 0 ); +// returns false ``` @@ -60,6 +66,10 @@ bool = isAlmostSameValue( NaN, NaN, 1 );
+## Notes + +- The function implements the [SameValue Algorithm][ecma-262-same-value-algorithm] as specified in ECMAScript 5. +
@@ -75,25 +85,32 @@ var EPS = require( '@stdlib/constants/float16/eps' ); var isAlmostSameValue = require( '@stdlib/number/float16/base/assert/is-almost-same-value' ); var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 ); -// returns true +console.log( bool ); +// => true bool = isAlmostSameValue( 1.0+EPS, 1.0, 1 ); -// returns true +console.log( bool ); +// => true bool = isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); -// returns false +console.log( bool ); +// => false bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 ); -// returns false +console.log( bool ); +// => false bool = isAlmostSameValue( -0.0, 0.0, 0 ); -// returns false +console.log( bool ); +// => false bool = isAlmostSameValue( 1.0, NaN, 1 ); -// returns false +console.log( bool ); +// => false bool = isAlmostSameValue( NaN, NaN, 1 ); -// returns true +console.log( bool ); +// => true ``` @@ -112,6 +129,8 @@ bool = isAlmostSameValue( NaN, NaN, 1 );