diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/README.md b/lib/node_modules/@stdlib/assert/is-almost-equal/README.md new file mode 100644 index 000000000000..ea87c2198d7a --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/README.md @@ -0,0 +1,172 @@ + + +# isAlmostEqual + +> Test if two arguments are approximately equal within a specified number of ULPs (units in the last place). + +
+ +## Usage + +```javascript +var isAlmostEqual = require( '@stdlib/assert/is-almost-equal' ); +``` + +#### isAlmostEqual( a, b, maxULP ) + +Tests if two arguments are approximately equal within a specified number of ULPs (units in the last place). + +```javascript +var EPS = require( '@stdlib/constants/float64/eps' ); + +var bool = isAlmostEqual( 1.0, 1.0+EPS, 1 ); +// returns true + +bool = isAlmostEqual( '', '', 0 ); +// returns true + +bool = isAlmostEqual( {}, {}, 1 ); +// returns false +``` + +The function returns `false` if either input value is `NaN` or, in the case of [complex numbers][@stdlib/complex], if either the real or imaginary component is `NaN`. + +```javascript +var Complex128 = require( '@stdlib/complex/float64/ctor' ); + +var bool = isAlmostEqual( NaN, 1.0, 1 ); +// returns false + +bool = isAlmostEqual( NaN, NaN, 1 ); +// returns false + +var z1 = new Complex128( NaN, 3.0 ); +var z2 = new Complex128( 1.0, 3.0 ); + +bool = isAlmostEqual( z1, z2, 1 ); +// returns false + +z1 = new Complex128( NaN, NaN ); +z2 = new Complex128( NaN, NaN ); + +bool = isAlmostEqual( z1, z2, 1 ); +// returns false +``` + +The function does not distinguish between `-0` and `+0`, treating them as equal. + +```javascript +var Complex128 = require( '@stdlib/complex/float64/ctor' ); + +var bool = isAlmostEqual( 0.0, -0.0, 0 ); +// returns true + +var z1 = new Complex128( 0.0, 0.0 ); +var z2 = new Complex128( -0.0, -0.0 ); + +bool = isAlmostEqual( z1, z2, 0 ); +// returns true +``` + +
+ + + +
+ +## Notes + +
+ + + +
+ +## Examples + + + +```javascript +var EPS = require( '@stdlib/constants/float64/eps' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var isAlmostEqual = require( '@stdlib/assert/is-almost-equal' ); + +console.log( isAlmostEqual( true, true, 0 ) ); +// => true + +console.log( isAlmostEqual( true, false, 1 ) ); +// => false + +console.log( isAlmostEqual( 'beep', 'beep', 1 ) ); +// => true + +console.log( isAlmostEqual( 1.0, 1.0+EPS, 1 ) ); +// => true + +console.log( isAlmostEqual( null, null, 0 ) ); +// => true + +console.log( isAlmostEqual( 0.0, -0.0, 0 ) ); +// => true + +console.log( isAlmostEqual( NaN, NaN, 1 ) ); +// => false + +var z1 = new Complex128( 1.0, 3.0+EPS ); +var z2 = new Complex128( 1.0+EPS, 3.0 ); +console.log( isAlmostEqual( z1, z2, 1 ) ); +// => true + +console.log( isAlmostEqual( {}, {}, 1 ) ); +// => false + +console.log( isAlmostEqual( [], [], 1 ) ); +// => false + +console.log( isAlmostEqual( isAlmostEqual, isAlmostEqual, 0 ) ); +// => true +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/is-almost-equal/benchmark/benchmark.js new file mode 100644 index 000000000000..b6b75a052451 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @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. +*/ + +/* eslint-disable no-empty-function */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isAlmostEqual = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var bool; + var v; + var i; + + values = [ + '', + '5', + 0, + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + new RegExp( '.*' ), // eslint-disable-line prefer-regex-literals + new Date(), + function noop() {} + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = values[ i%values.length ]; + bool = isAlmostEqual( 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/assert/is-almost-equal/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-almost-equal/docs/repl.txt new file mode 100644 index 000000000000..c4c2108cae5d --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( a, b, maxULP ) + Tests if two arguments are approximately equal within a specified number of + ULPs (units in the last place). + + The function returns `false` if either input value is `NaN` or in the case + of complex numbers, if either the real or imaginary component is `NaN`. + + The function does not distinguish between `-0` and `+0`, treating them as + equal. + + Parameters + ---------- + a: any + First input value. + + b: any + Second input value. + + maxULP: integer + Maximum allowed ULP difference. + + Returns + ------- + bool: boolean + Boolean indicating whether two arguments are approximately equal within + a specified number of ULPs. + + Examples + -------- + > var bool = {{alias}}( true, true, 0 ) + true + > bool = {{alias}}( 1+{{alias:@stdlib/constants/float64/eps}}, 1, 1 ) + true + > bool = {{alias}}( {}, {}, 1 ) + false + > bool = {{alias}}( 0.0, -0.0, 0 ) + true + > bool = {{alias}}( NaN, 1.0, 1 ) + false + > bool = {{alias}}( NaN, NaN, 0 ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-almost-equal/docs/types/index.d.ts new file mode 100644 index 000000000000..dc7f5bc402d3 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/docs/types/index.d.ts @@ -0,0 +1,60 @@ +/* +* @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 approximately equal within a specified number of ULPs (units in the last place). +* +* ## Notes +* +* - The function returns `false` if either input value is `NaN` or in the case of complex numbers, if either the real or imaginary component is `NaN`. +* - The function does not distinguish between `-0` and `+0`, treating them as equal. +* +* @param a - first input value +* @param b - second input value +* @param maxULP - maximum allowed ULP difference +* @returns boolean indicating whether two arguments are approximately equal within a specified number of ULPs +* +* @example +* var EPS = require( '@stdlib/constants/float64/eps' ); +* +* var bool = isAlmostEqual( 1.0, 1.0+EPS, 0 ); +* // returns false +* +* bool = isAlmostEqual( 1.0, 1.0+EPS, 1 ); +* // returns true +* +* bool = isAlmostEqual( {}, {}, 0 ); +* // returns false +* +* bool = isAlmostEqual( -0.0, 0.0, 0 ); +* // returns true +* +* bool = isAlmostEqual( NaN, NaN, 0 ); +* // returns false +* +* bool = isAlmostEqual( [], [], 1 ); +* // returns false +*/ +declare function isAlmostEqual( a: any, b: any, maxULP: number ): boolean; + + +// EXPORTS // + +export = isAlmostEqual; diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-almost-equal/docs/types/test.ts new file mode 100644 index 000000000000..fad7a7df2ae5 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/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 isAlmostEqual = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isAlmostEqual( 3.14, 3.14, 1 ); // $ExpectType boolean + isAlmostEqual( null, null, 0 ); // $ExpectType boolean + isAlmostEqual( 'beep', 'boop', 2 ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + isAlmostEqual( 3.14, 3.14, '1' ); // $ExpectError + isAlmostEqual( 3.14, 3.14, true ); // $ExpectError + isAlmostEqual( 3.14, 3.14, false ); // $ExpectError + isAlmostEqual( 3.14, 3.14, null ); // $ExpectError + isAlmostEqual( 3.14, 3.14, undefined ); // $ExpectError + isAlmostEqual( 3.14, 3.14, [] ); // $ExpectError + isAlmostEqual( 3.14, 3.14, {} ); // $ExpectError + isAlmostEqual( 3.14, 3.14, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isAlmostEqual(); // $ExpectError + isAlmostEqual( 3.14 ); // $ExpectError + isAlmostEqual( 'beep', 'beep' ); // $ExpectError + isAlmostEqual( 3.14, 3.14, 1, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/examples/index.js b/lib/node_modules/@stdlib/assert/is-almost-equal/examples/index.js new file mode 100644 index 000000000000..ebb3aa2f1b44 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/examples/index.js @@ -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. +*/ + +'use strict'; + +var EPS = require( '@stdlib/constants/float64/eps' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var isAlmostEqual = require( './../lib' ); + +console.log( isAlmostEqual( true, true, 0 ) ); +// => true + +console.log( isAlmostEqual( true, false, 1 ) ); +// => false + +console.log( isAlmostEqual( 'beep', 'beep', 1 ) ); +// => true + +console.log( isAlmostEqual( 1.0, 1.0+EPS, 1 ) ); +// => true + +console.log( isAlmostEqual( null, null, 0 ) ); +// => true + +console.log( isAlmostEqual( 0.0, -0.0, 0 ) ); +// => true + +console.log( isAlmostEqual( NaN, NaN, 1 ) ); +// => false + +var z1 = new Complex128( 1.0, 3.0+EPS ); +var z2 = new Complex128( 1.0+EPS, 3.0 ); +console.log( isAlmostEqual( z1, z2, 1 ) ); +// => true + +console.log( isAlmostEqual( {}, {}, 1 ) ); +// => false + +console.log( isAlmostEqual( [], [], 1 ) ); +// => false + +console.log( isAlmostEqual( isAlmostEqual, isAlmostEqual, 0 ) ); +// => true diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/lib/index.js b/lib/node_modules/@stdlib/assert/is-almost-equal/lib/index.js new file mode 100644 index 000000000000..05618eb24e37 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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 approximately equal within a specified number of ULPs (units in the last place). +* +* @module @stdlib/assert/is-almost-equal +* +* @example +* var EPS = require( '@stdlib/constants/float64/eps' ); +* var isAlmostEqual = require( '@stdlib/assert/is-almost-equal' ); +* +* var bool = isAlmostEqual( 1.0, 1.0+EPS, 0 ); +* // returns false +* +* bool = isAlmostEqual( 1.0, 1.0+EPS, 1 ); +* // returns true +* +* bool = isAlmostEqual( {}, {}, 0 ); +* // returns false +* +* bool = isAlmostEqual( -0.0, 0.0, 0 ); +* // returns true +* +* bool = isAlmostEqual( NaN, NaN, 0 ); +* // returns false +* +* bool = isAlmostEqual( [], [], 1 ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/lib/main.js b/lib/node_modules/@stdlib/assert/is-almost-equal/lib/main.js new file mode 100644 index 000000000000..c5891d2091a9 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/lib/main.js @@ -0,0 +1,85 @@ +/** +* @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 isAlmostEqualComplex64 = require( '@stdlib/complex/float32/base/assert/is-almost-equal' ); +var isAlmostEqualComplex128 = require( '@stdlib/complex/float64/base/assert/is-almost-equal' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isAlmostEqualF64 = require( '@stdlib/number/float64/base/assert/is-almost-equal' ); +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); + + +// MAIN // + +/** +* Tests if two arguments are approximately equal within a specified number of ULPs (units in the last place). +* +* ## Notes +* +* - The function returns `false` if either input value is `NaN` or, in the case of complex numbers, if either the real or imaginary component is `NaN`. +* - The function does not distinguish between `-0` and `+0`, treating them as equal. +* +* @param {*} a - first input value +* @param {*} b - second input value +* @param {NonNegativeInteger} maxULP - maximum allowed ULP difference +* @returns {boolean} boolean indicating whether two arguments are approximately equal within a specified number of ULPs +* +* @example +* var EPS = require( '@stdlib/constants/float64/eps' ); +* +* var bool = isAlmostEqual( 1.0, 1.0+EPS, 0 ); +* // returns false +* +* bool = isAlmostEqual( 1.0, 1.0+EPS, 1 ); +* // returns true +* +* bool = isAlmostEqual( {}, {}, 0 ); +* // returns false +* +* bool = isAlmostEqual( -0.0, 0.0, 0 ); +* // returns true +* +* bool = isAlmostEqual( NaN, NaN, 0 ); +* // returns false +* +* bool = isAlmostEqual( [], [], 1 ); +* // returns false +*/ +function isAlmostEqual( a, b, maxULP ) { + if ( a === b ) { + return true; + } + if ( isNumber( a ) && isNumber( b ) ) { + return isAlmostEqualF64( a, b, maxULP ); + } + if ( isComplexLike( a ) && isComplexLike( b ) ) { + if ( a.BYTES_PER_ELEMENT === 4 && b.BYTES_PER_ELEMENT === 4 ) { + return isAlmostEqualComplex64( a, b, maxULP ); + } + return isAlmostEqualComplex128( a, b, maxULP ); + } + return false; +} + + +// EXPORTS // + +module.exports = isAlmostEqual; diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/package.json b/lib/node_modules/@stdlib/assert/is-almost-equal/package.json new file mode 100644 index 000000000000..a556f5e58a48 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/assert/is-almost-equal", + "version": "0.0.0", + "description": "Test if two arguments 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", + "isequal", + "isalmostequal", + "isstrictequal", + "type", + "check", + "valid", + "validate", + "test" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-almost-equal/test/test.js b/lib/node_modules/@stdlib/assert/is-almost-equal/test/test.js new file mode 100644 index 000000000000..bb41d61ac875 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-almost-equal/test/test.js @@ -0,0 +1,194 @@ +/** +* @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. +*/ + +/* eslint-disable no-new-wrappers */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var EPS_F64 = require( '@stdlib/constants/float64/eps' ); +var EPS_F32 = require( '@stdlib/constants/float32/eps' ); +var Number = require( '@stdlib/number/ctor' ); +var Boolean = require( '@stdlib/boolean/ctor' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var isAlmostEqual = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isAlmostEqual, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided two arguments which are the same value irrespective of the specified number of ULPs', function test( t ) { + var values; + var i; + + values = [ + '', + 'beep', + 5, + 3.14, + -3.14, + 0.0, + -0.0, + true, + false, + null, + void 0, + [], + {}, + function noop() {}, + new Date(), + /.*/, + new Complex128( 5.0, 3.0 ), + new Complex64( 5.0, 2.0 ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isAlmostEqual( values[ i ], values[ i ], 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( values[ i ], values[ i ], 1 ), true, 'returns expected value' ); + } + + t.strictEqual( isAlmostEqual( new Complex128( 5.0, 3.0 ), new Complex128( 5.0, 3.0 ), 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex128( 5.0, 3.0 ), new Complex128( 5.0, 3.0 ), 1 ), true, 'returns expected value' ); + + t.strictEqual( isAlmostEqual( new Complex64( 5.0, 3.0 ), new Complex64( 5.0, 3.0 ), 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex64( 5.0, 3.0 ), new Complex64( 5.0, 3.0 ), 1 ), true, 'returns expected value' ); + + t.strictEqual( isAlmostEqual( new Complex64( 5.0, 3.0 ), new Complex128( 5.0, 3.0 ), 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex64( 5.0, 3.0 ), new Complex128( 5.0, 3.0 ), 1 ), true, 'returns expected value' ); + + t.strictEqual( isAlmostEqual( new Complex128( 5.0, 3.0 ), new Complex64( 5.0, 3.0 ), 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex128( 5.0, 3.0 ), new Complex64( 5.0, 3.0 ), 1 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `true` if provided two arguments which are approximately equal within a specified number of ULPs', function test( t ) { + t.strictEqual( isAlmostEqual( 1.0, 1.0+EPS_F64, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( 1.0+EPS_F64, 1.0, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( 1.0, 1.0+EPS_F64+EPS_F64, 2 ), true, 'returns expected value' ); + + t.strictEqual( isAlmostEqual( new Complex128( 1.0, 3.0 ), new Complex128( 1.0+EPS_F64, 3.0 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex64( 1.0, 3.0 ), new Complex64( 1.0+EPS_F32, 3.0 ), 1 ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if provided two arguments which are not approximately equal within a specified number of ULPs', function test( t ) { + var a; + var b; + var i; + + a = [ + '', + 'beep', + new String( 'beep' ), + 5, + 3.14, + -3.14, + new Number( 5 ), + true, + false, + new Boolean( true ), + null, + void 0, + [], + {}, + function noop() {}, + new Date(), + /.*/, + new Complex128( 5.0, 3.0 ), + new Complex64( 5.0, 2.0 ) + ]; + b = [ + 'abc', + 'boop', + new String( 'beep' ), + -5, + -3.14, + 3.14, + new Number( 5 ), + false, + true, + new Boolean( true ), + void 0, + null, + [], + {}, + function noop() {}, + new Date(), + /.*/, + new Complex128( -5.0, 3.0 ), + new Complex64( 5.0, -2.0 ) + ]; + for ( i = 0; i < a.length; i++ ) { + t.strictEqual( isAlmostEqual( a[ i ], b[ i ], 1 ), false, 'returns expected value' ); + } + + t.strictEqual( isAlmostEqual( 1.0, 1.0+EPS_F64+EPS_F64, 1 ), false, 'returns expected value' ); + t.strictEqual( isAlmostEqual( 1.0+EPS_F64+EPS_F64, 1.0, 1 ), false, 'returns expected value' ); + + t.strictEqual( isAlmostEqual( new Complex128( 1.0, 3.0 ), new Complex128( 1.0+EPS_F64+EPS_F64, 3.0 ), 1 ), false, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex64( 1.0, 3.0 ), new Complex64( 1.0+EPS_F32+EPS_F32, 3.0 ), 1 ), false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if either input value is `NaN` or, in the case of complex numbers, if either the real or imaginary component is `NaN`', function test( t ) { + var a; + var b; + var i; + + a = [ + NaN, + NaN, + new Complex128( NaN, 3.0 ), + new Complex64( 5.0, NaN ), + new Complex128( NaN, NaN ), + new Complex64( NaN, NaN ) + ]; + b = [ + NaN, + 1.0, + new Complex128( 1.0, 2.0 ), + new Complex64( 3.0, 4.0 ), + new Complex128( NaN, NaN ), + new Complex64( NaN, NaN ) + ]; + for ( i = 0; i < a.length; i++ ) { + t.strictEqual( isAlmostEqual( a[ i ], b[ i ], 1 ), false, 'returns expected value' ); + } + + t.end(); +}); + +tape( 'the function does not distinguish between `-0` and `+0`', function test( t ) { + t.strictEqual( isAlmostEqual( -0.0, 0.0, 0 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( 0.0, -0.0, 0 ), true, 'returns expected value' ); + + t.strictEqual( isAlmostEqual( new Complex128( -0.0, 3.0 ), new Complex128( 0.0, 3.0 ), 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( new Complex64( -0.0, 3.0 ), new Complex64( 0.0, 3.0 ), 1 ), true, 'returns expected value' ); + + t.end(); +});