From af13c45b812b1242b6b56c983840b13151030abf Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Thu, 17 Jul 2025 21:58:05 +0530 Subject: [PATCH 1/2] feat: add `assert/is-almost-equal-float32array` --- 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 --- --- .../is-almost-equal-float32array/README.md | 117 ++++++++++++++++++ .../benchmark/benchmark.length.js | 97 +++++++++++++++ .../docs/repl.txt | 43 +++++++ .../docs/types/index.d.ts | 57 +++++++++ .../docs/types/test.ts | 49 ++++++++ .../examples/index.js | 40 ++++++ .../is-almost-equal-float32array/lib/index.js | 54 ++++++++ .../is-almost-equal-float32array/lib/main.js | 67 ++++++++++ .../is-almost-equal-float32array/package.json | 77 ++++++++++++ .../is-almost-equal-float32array/test/test.js | 114 +++++++++++++++++ 10 files changed, 715 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/README.md create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/package.json create mode 100644 lib/node_modules/@stdlib/assert/is-almost-equal-float32array/test/test.js diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/README.md b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/README.md new file mode 100644 index 000000000000..a96e995c4ac3 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/README.md @@ -0,0 +1,117 @@ + + +# isAlmostEqualFloat32Array + +> Test if two arguments are both [Float32Arrays][@stdlib/array/float32] and contain respective elements which are [approximately equal][@stdlib/assert/is-almost-equal] within a specified number of ULPs (units in the last place). + +
+ +## Usage + +```javascript +var isAlmostEqualFloat32Array = require( '@stdlib/assert/is-almost-equal-float32array' ); +``` + +#### isAlmostEqualFloat32Array( v1, v2, maxULP ) + +Tests if two arguments are both [Float32Arrays][@stdlib/array/float32] and contain respective elements which are [approximately equal][@stdlib/assert/is-almost-equal] within a specified number of ULPs (units in the last place). + +```javascript +var EPS = require( '@stdlib/constants/float32/eps' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0 ] ); +var y = new Float32Array( [ 1.0+EPS, 2.0 ] ); + +var bool = isAlmostEqualFloat32Array( x, y, 0 ); +// returns false + +bool = isAlmostEqualFloat32Array( x, y, 1 ); +// returns true + +bool = isAlmostEqualFloat32Array( x, [ 1.0, 2.0 ], 1 ); +// returns false +``` + +
+ + + +
+ +## Notes + +- The function returns `false` if either input value is a `Float32Array` containing `NaN`. +- The function does not distinguish between `-0` and `+0`, treating them as equal. + +
+ + + +
+ +## Examples + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var isAlmostEqualFloat32Array = require( '@stdlib/assert/is-almost-equal-float32array' ); + +var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +var y = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +var out = isAlmostEqualFloat32Array( x, y, 0 ); +// returns true + +x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); +y = new Float32Array( [ 0.0, -0.0, 0.0 ] ); +out = isAlmostEqualFloat32Array( x, y, 1 ); +// returns true + +x = new Float32Array( [ NaN, NaN, NaN ] ); +y = new Float32Array( [ NaN, NaN, NaN ] ); +out = isAlmostEqualFloat32Array( x, y, 0 ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/benchmark/benchmark.length.js new file mode 100644 index 000000000000..1ab375b8731c --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/benchmark/benchmark.length.js @@ -0,0 +1,97 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var Float32Array = require( '@stdlib/array/float32' ); +var pkg = require( './../package.json' ).name; +var isAlmostEqualFloat32Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = new Float32Array( zeroTo( len ) ); + var y = new Float32Array( zeroTo( len ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isAlmostEqualFloat32Array( x, y, 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(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt new file mode 100644 index 000000000000..ca1d282c2bef --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( v1, v2, maxULP ) + Tests if two arguments are both Float32Arrays and contain respective + elements which are approximately equal within a specified number of ULPs + (units in the last place). + + The function returns `false` if either input value is a `Float32Array` + containing `NaN`. + + The function does not distinguish between `-0` and `+0`, treating them as + equal. + + Parameters + ---------- + v1: any + First input value. + + v2: any + Second input value. + + maxULP: integer + Maximum allowed ULP difference. + + Returns + ------- + bool: boolean + Boolean result. + + Examples + -------- + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] ); + > var bool = {{alias}}( x, y, 1 ) + true + + > x = new {{alias:@stdlib/array/float32}}( [ NaN, NaN, NaN ] ); + > y = new {{alias:@stdlib/array/float32}}( [ NaN, NaN, NaN ] ); + > bool = {{alias}}( x, y, 1 ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts new file mode 100644 index 000000000000..a82d1d082504 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts @@ -0,0 +1,57 @@ +/* +* @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 + +/** +* Tests if two arguments are both Float32Arrays and contain respective elements which are approximately equal within a specified number of ULPs (units in the last place). +* +* ## Notes +* +* - The function returns `false` if either input value is a `Float32Array` containing `NaN`. +* - The function does not distinguish between `-0` and `+0`, treating them as equal. +* +* @param v1 - first input value +* @param v2 - second input value +* @param maxULP - maximum allowed ULP difference +* @returns boolean result +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = isAlmostEqualFloat32Array( x, y, 0 ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Array( [ 1.0, 2.0, 4.0 ] ); +* +* var out = isAlmostEqualFloat32Array( x, y, 1 ); +* // returns false +*/ +declare function isAlmostEqualFloat32Array( v1: any, v2: any, maxULP: number ): boolean; + + +// EXPORTS // + +export = isAlmostEqualFloat32Array; diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/test.ts new file mode 100644 index 000000000000..13d98d3a3aec --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/test.ts @@ -0,0 +1,49 @@ +/* +* @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 isAlmostEqualFloat32Array = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isAlmostEqualFloat32Array( 3.14, 3.14, 1 ); // $ExpectType boolean + isAlmostEqualFloat32Array( null, null, 1 ); // $ExpectType boolean + isAlmostEqualFloat32Array( 'beep', 'boop', 1 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + isAlmostEqualFloat32Array( 3.14, 3.14, '1' ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, true ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, false ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, null ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, undefined ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, [] ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, {} ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isAlmostEqualFloat32Array(); // $ExpectError + isAlmostEqualFloat32Array( 3.14 ); // $ExpectError + isAlmostEqualFloat32Array( 3.14, 3.14 ); // $ExpectError + isAlmostEqualFloat32Array( 'beep', 'beep', 2, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/examples/index.js b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/examples/index.js new file mode 100644 index 000000000000..17b42765a0f6 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 Float32Array = require( '@stdlib/array/float32' ); +var isAlmostEqualFloat32Array = require( './../lib' ); + +var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +var y = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +var out = isAlmostEqualFloat32Array( x, y, 0 ); +console.log( out ); +// => true + +x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); +y = new Float32Array( [ 0.0, -0.0, 0.0 ] ); +out = isAlmostEqualFloat32Array( x, y, 1 ); +console.log( out ); +// => true + +x = new Float32Array( [ NaN, NaN, NaN ] ); +y = new Float32Array( [ NaN, NaN, NaN ] ); +out = isAlmostEqualFloat32Array( x, y, 0 ); +console.log( out ); +// => false diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/index.js b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/index.js new file mode 100644 index 000000000000..2a4f63a92299 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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'; + +/** +* Test if two arguments are both Float32Arrays and contain respective elements which are approximately equal within a specified number of ULPs (units in the last place). +* +* @module @stdlib/assert/is-almost-equal-float32array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var isAlmostEqualFloat32Array = require( '@stdlib/assert/is-almost-equal-float32array' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = isAlmostEqualFloat32Array( x, y, 1 ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var isAlmostEqualFloat32Array = require( '@stdlib/assert/is-almost-equal-float32array' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Array( [ 1.0, 2.0, 4.0 ] ); +* +* var out = isAlmostEqualFloat32Array( x, y, 1 ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js new file mode 100644 index 000000000000..2c6762bf0cd5 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js @@ -0,0 +1,67 @@ +/** +* @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 isFloat32Array = require( '@stdlib/assert/is-float32array' ); +var hasAlmostEqualValues = require( '@stdlib/array/base/assert/has-almost-equal-values' ); + + +// MAIN // + +/** +* Tests if two arguments are both Float32Arrays and contain respective elements which are approximately equal within a specified number of ULPs (units in the last place). +* +* ## Notes +* +* - The function returns `false` if either input value is a `Float32Array` containing `NaN`. +* - The function does not distinguish between `-0` and `+0`, treating them as equal. +* +* @param {*} v1 - first value +* @param {*} v2 - second value +* @param {NonNegativeInteger} maxULP - maximum allowed ULP difference +* @returns {boolean} boolean result +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = isAlmostEqualFloat32Array( x, y, 0 ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Float32Array( [ 1.0, 2.0, 4.0 ] ); +* +* var out = isAlmostEqualFloat32Array( x, y, 1 ); +* // returns false +*/ +function isAlmostEqualFloat32Array( v1, v2, maxULP ) { + return ( isFloat32Array( v1 ) && isFloat32Array( v2 ) && hasAlmostEqualValues( v1, v2, maxULP ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = isAlmostEqualFloat32Array; diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/package.json b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/package.json new file mode 100644 index 000000000000..cf6db24307f5 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/assert/is-almost-equal-float32array", + "version": "0.0.0", + "description": "Test if two arguments are both Float32Arrays and contain respective elements which are approximately equal 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", + "issamevalue", + "isequal", + "isstrictequal", + "type", + "check", + "valid", + "validate", + "test", + "typed", + "array", + "float32" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/test/test.js b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/test/test.js new file mode 100644 index 000000000000..817f0bf57225 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/test/test.js @@ -0,0 +1,114 @@ +/** +* @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 typedarray = require( '@stdlib/array/typed' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var isAlmostEqualFloat32Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isAlmostEqualFloat32Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided two Float32Arrays having almost equal values', function test( t ) { + var x; + var y; + + x = typedarray( [ 1.0, 2.0, 3.0 ], 'float32' ); + t.strictEqual( isAlmostEqualFloat32Array( x, x, 0 ), true, 'returns expected value' ); + + x = typedarray( [ 1.0, 2.0, 3.0 ], 'float32' ); + y = typedarray( [ 1.0, 2.0, 3.0 ], 'float32' ); + t.strictEqual( isAlmostEqualFloat32Array( x, y, 0 ), true, 'returns expected value' ); + + x = typedarray( [ -0.0, 0.0, -0.0 ], 'float32' ); + y = typedarray( [ -0.0, 0.0, -0.0 ], 'float32' ); + t.strictEqual( isAlmostEqualFloat32Array( x, y, 0 ), true, 'returns expected value' ); + + x = typedarray( [ 1.0, 2.0, 3.0 ], 'float32' ); + y = typedarray( [ 1.0+EPS, 2.0, 3.0 ], 'float32' ); + t.strictEqual( isAlmostEqualFloat32Array( x, y, 1 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if not provided two Float32Arrays having almost equal values', function test( t ) { + var x; + var y; + var i; + + x = [ + '', + 'beep', + 5, + 3.14, + -3.14, + 0.0, + -0.0, + true, + false, + null, + void 0, + [], + {}, + function noop() {}, + typedarray( 10, 'float64' ), + typedarray( 10, 'int32' ), + typedarray( 10, 'float64' ), + typedarray( [ 1.0, 2.0, 3.0 ], 'float32' ), + typedarray( [ -0.0, -0.0, -0.0 ], 'float32' ), + typedarray( [ 1.0, 2.0, 3.0 ], 'float32' ), + typedarray( [ NaN, NaN, NaN ], 'float32' ) + ]; + y = [ + 'abc', + 'boop', + -5, + -3.14, + 3.14, + -0.0, + 0.0, + false, + true, + void 0, + null, + [], + {}, + function noop() {}, + typedarray( 10, 'float64' ), + typedarray( 10, 'int32' ), + typedarray( 10, 'float32' ), + typedarray( [ 2.0, 4.0, 6.0 ], 'float32' ), + typedarray( [ 0.0, 0.0, 1.0 ], 'float32' ), + typedarray( [ 1.0+EPS+EPS, 2.0, 3.0 ], 'float32' ), + typedarray( [ NaN, NaN, NaN ], 'float32' ) + ]; + for ( i = 0; i < x.length; i++ ) { + t.strictEqual( isAlmostEqualFloat32Array( x[ i ], y[ i ], 1 ), false, 'returns expected value' ); + } + t.end(); +}); From a8842412a3d89ae4ce5166254f010c1bd389e75c Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 18 Jul 2025 09:40:54 +0530 Subject: [PATCH 2/2] docs: update function return annotation --- 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: passed - 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 --- --- .../@stdlib/assert/is-almost-equal-float32array/docs/repl.txt | 2 +- .../assert/is-almost-equal-float32array/docs/types/index.d.ts | 2 +- .../@stdlib/assert/is-almost-equal-float32array/lib/main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt index ca1d282c2bef..acb8e57874d1 100644 --- a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/repl.txt @@ -24,7 +24,7 @@ Returns ------- bool: boolean - Boolean result. + Boolean indicating whether two arguments are approximately equal. Examples -------- diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts index a82d1d082504..f3f78babffc2 100644 --- a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/docs/types/index.d.ts @@ -29,7 +29,7 @@ * @param v1 - first input value * @param v2 - second input value * @param maxULP - maximum allowed ULP difference -* @returns boolean result +* @returns boolean indicating whether two arguments are approximately equal * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js index 2c6762bf0cd5..38b402b5e29e 100644 --- a/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js +++ b/lib/node_modules/@stdlib/assert/is-almost-equal-float32array/lib/main.js @@ -37,7 +37,7 @@ var hasAlmostEqualValues = require( '@stdlib/array/base/assert/has-almost-equal- * @param {*} v1 - first value * @param {*} v2 - second value * @param {NonNegativeInteger} maxULP - maximum allowed ULP difference -* @returns {boolean} boolean result +* @returns {boolean} boolean indicating whether two arguments are approximately equal * * @example * var Float32Array = require( '@stdlib/array/float32' );