diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/README.md b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/README.md new file mode 100644 index 000000000000..f8cc6d2cd027 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/README.md @@ -0,0 +1,146 @@ + + +# ulpdiff + +> Compute the number of representable [double-precision][double-precision] floating-point values that separate two [double-precision][double-precision] floating-point numbers along the real number line. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var ulpdiff = require( '@stdlib/number/float64/base/ulp-difference' ); +``` + +#### ulpdiff( x, y ) + +Computes the number of representable [double-precision][double-precision] floating-point values that separate two [double-precision][double-precision] floating-point numbers along the real number line. + +```javascript +var EPS = require( '@stdlib/constants/float64/eps' ); + +var d = ulpdiff( 1.0, 1.0+EPS ); +// returns 1.0 + +d = ulpdiff( 1.0+EPS, 1.0 ); +// returns 1.0 + +d = ulpdiff( 1.0, 1.0+EPS+EPS ); +// returns 2.0 + +d = ulpdiff( 1.0, NaN ); +// returns NaN + +d = ulpdiff( NaN, 1.0 ); +// returns NaN + +d = ulpdiff( NaN, NaN ); +// returns NaN +``` + +
+ + + + + +
+ +## Notes + +- Adjacent [double-precision][double-precision] floating-point numbers differ by `1` [ulp][ulp] (unit in the last place). +- Signed zeros differ only in the sign bit but are considered numerically equal, and thus their ULP difference is `0`. + +
+ + + + + +
+ +## Examples + + + +```javascript +var EPS = require( '@stdlib/constants/float64/eps' ); +var SMALLEST_SUBNORMAL = require( '@stdlib/constants/float64/smallest-subnormal' ); +var ulpdiff = require( '@stdlib/number/float64/base/ulp-difference' ); + +var d = ulpdiff( 1.0, 1.0+EPS ); +console.log( d ); +// => 1.0 + +d = ulpdiff( 5.8364e-319, 5.8367e-319 ); +console.log( d ); +// => 6.0 + +d = ulpdiff( 0.0, SMALLEST_SUBNORMAL ); +console.log( d ); +// => 1.0 + +d = ulpdiff( 0.0, -0.0 ); +console.log( d ); +// => 0.0 + +d = ulpdiff( SMALLEST_SUBNORMAL, -SMALLEST_SUBNORMAL ); +console.log( d ); +// => 2.0 +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/benchmark/benchmark.js b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/benchmark/benchmark.js new file mode 100644 index 000000000000..534a4cb8767a --- /dev/null +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/benchmark/benchmark.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var ulpdiff = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var y; + var i; + + x = uniform( 100, -500.0, 500.0 ); + y = uniform( 100, -500.0, 500.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = ulpdiff( x[ i%x.length ], y[ i%y.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/repl.txt b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/repl.txt new file mode 100644 index 000000000000..fa487d09447e --- /dev/null +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/repl.txt @@ -0,0 +1,45 @@ + +{{alias}}( x, y ) + Computes the number of representable double-precision floating-point values + that separate two double-precision floating-point numbers along the real + number line. + + Adjacent double-precision floating-point numbers differ by 1 ulp (unit in + the last place). + + Signed zeros differ only in the sign bit but are considered numerically + equal, and thus their ULP difference is 0. + + If provided `NaN` as any argument, the function returns `NaN`. + + Parameters + ---------- + x: number + First input value. + + y: number + Second input value. + + Returns + ------- + z: number + Result. + + Examples + -------- + > var v = {{alias}}( 1.0, 1.0+{{alias:@stdlib/constants/float64/eps}} ) + 1.0 + > v = {{alias}}( 1.0+{{alias:@stdlib/constants/float64/eps}}, 1.0 ) + 1.0 + > v = {{alias}}( 1.0, 1.0+{{alias:@stdlib/constants/float64/eps}}*2.0 ) + 2.0 + > v = {{alias}}( 1.0, NaN ) + NaN + > v = {{alias}}( NaN, 1.0 ) + NaN + > v = {{alias}}( NaN, NaN ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/types/index.d.ts b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/types/index.d.ts new file mode 100644 index 000000000000..8c3af4a5ed10 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/types/index.d.ts @@ -0,0 +1,59 @@ +/* +* @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 + +/** +* Computes the number of representable double-precision floating-point values that separate two double-precision floating-point numbers along the real number line. +* +* ## Notes +* +* - Adjacent double-precision floating-point numbers differ by 1 ulp (unit in the last place). +* - Signed zeros differ only in the sign bit but are considered numerically equal, and thus their ULP difference is 0. +* +* @param x - first input value +* @param y - second input value +* @returns result +* +* @example +* var EPS = require( '@stdlib/constants/float64/eps' ); +* +* var d = ulpdiff( 1.0, 1.0+EPS ); +* // returns 1.0 +* +* d = ulpdiff( 1.0+EPS, 1.0 ); +* // returns 1.0 +* +* d = ulpdiff( 1.0, 1.0+EPS+EPS ); +* // returns 2.0 +* +* d = ulpdiff( 1.0, NaN ); +* // returns NaN +* +* d = ulpdiff( NaN, 1.0 ); +* // returns NaN +* +* d = ulpdiff( NaN, NaN ); +* // returns NaN +*/ +declare function ulpdiff( x: number, y: number ): number; + + +// EXPORTS // + +export = ulpdiff; diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/types/test.ts b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/types/test.ts new file mode 100644 index 000000000000..239f60260c44 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/docs/types/test.ts @@ -0,0 +1,58 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import ulpdiff = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + ulpdiff( 8.0, 8.0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + ulpdiff( true, 5.0 ); // $ExpectError + ulpdiff( false, 5.0 ); // $ExpectError + ulpdiff( null, 5.0 ); // $ExpectError + ulpdiff( undefined, 5.0 ); // $ExpectError + ulpdiff( '5', 5.0 ); // $ExpectError + ulpdiff( [], 5.0 ); // $ExpectError + ulpdiff( {}, 5.0 ); // $ExpectError + ulpdiff( ( x: number ): number => x, 5.0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + ulpdiff( 5.0, true ); // $ExpectError + ulpdiff( 5.0, false ); // $ExpectError + ulpdiff( 5.0, null ); // $ExpectError + ulpdiff( 5.0, undefined ); // $ExpectError + ulpdiff( 5.0, '5' ); // $ExpectError + ulpdiff( 5.0, [] ); // $ExpectError + ulpdiff( 5.0, {} ); // $ExpectError + ulpdiff( 5.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + ulpdiff(); // $ExpectError + ulpdiff( 5.0 ); // $ExpectError + ulpdiff( 5.0, 5.0, 5.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/examples/index.js b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/examples/index.js index 3c936580e25c..da1024dd9af3 100644 --- a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/examples/index.js +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/examples/index.js @@ -24,12 +24,20 @@ var ulpdiff = require( './../lib' ); var d = ulpdiff( 1.0, 1.0+EPS ); console.log( d ); +// => 1.0 d = ulpdiff( 5.8364e-319, 5.8367e-319 ); console.log( d ); +// => 6.0 d = ulpdiff( 0.0, SMALLEST_SUBNORMAL ); console.log( d ); +// => 1.0 d = ulpdiff( 0.0, -0.0 ); console.log( d ); +// => 0.0 + +d = ulpdiff( SMALLEST_SUBNORMAL, -SMALLEST_SUBNORMAL ); +console.log( d ); +// => 2.0 diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/lib/main.js b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/lib/main.js index e019343cf868..4ae1de4716e9 100644 --- a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/lib/main.js +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/lib/main.js @@ -144,6 +144,7 @@ function subtract( wa, wb, wc ) { * ## Notes * * - Adjacent double-precision floating-point numbers differ by 1 ulp (unit in the last place). +* - Signed zeros differ only in the sign bit but are considered numerically equal, and thus their ULP difference is 0. * * @param {number} x - first value * @param {number} y - second value diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/package.json b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/package.json index 8f00116961cc..a7ca0cf64d55 100644 --- a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/package.json +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/package.json @@ -15,8 +15,11 @@ ], "main": "./lib", "directories": { + "benchmark": "./benchmark", + "doc": "./docs", "example": "./examples", - "lib": "./lib" + "lib": "./lib", + "test": "./test" }, "types": "./docs/types", "scripts": {}, diff --git a/lib/node_modules/@stdlib/number/float64/base/ulp-difference/test/test.js b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/test/test.js new file mode 100644 index 000000000000..b5bef31b1c27 --- /dev/null +++ b/lib/node_modules/@stdlib/number/float64/base/ulp-difference/test/test.js @@ -0,0 +1,116 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveFinite = require( '@stdlib/assert/is-positive-finite' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var SMALLEST_SUBNORMAL = require( '@stdlib/constants/float64/smallest-subnormal' ); +var MAX_VALUE = require( '@stdlib/constants/float64/max' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var ulpdiff = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ulpdiff, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the ULP difference between two double-precision floating-point numbers', function test( t ) { + t.strictEqual( ulpdiff( 1.0, 1.0+EPS ), 1.0, 'returns expected value' ); + t.strictEqual( ulpdiff( 1.0+EPS, 1.0 ), 1.0, 'returns expected value' ); + + t.strictEqual( ulpdiff( 1.0, 1.0+( EPS*2.0 ) ), 2.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -1.0, -1.0+EPS ), 2.0, 'returns expected value' ); + + t.strictEqual( ulpdiff( -1.0, -1.0-( EPS*2.0 ) ), 2.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -1.0, -1.0+( EPS*2.0 ) ), 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles signed zeros', function test( t ) { + t.strictEqual( ulpdiff( 0.0, -0.0 ), 0.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -0.0, 0.0 ), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `0` for identical values', function test( t ) { + t.strictEqual( ulpdiff( 5.0, 5.0 ), 0.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -5.0, -5.0 ), 0.0, 'returns expected value' ); + t.strictEqual( ulpdiff( 0.0, 0.0 ), 0.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -0.0, -0.0 ), 0.0, 'returns expected value' ); + + t.strictEqual( ulpdiff( SMALLEST_SUBNORMAL, SMALLEST_SUBNORMAL ), 0.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -SMALLEST_SUBNORMAL, -SMALLEST_SUBNORMAL ), 0.0, 'returns expected value' ); + + t.strictEqual( ulpdiff( PINF, PINF ), 0.0, 'returns expected value' ); + t.strictEqual( ulpdiff( NINF, NINF ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles infinities', function test( t ) { + t.strictEqual( isPositiveFinite( ulpdiff( 5.0, PINF ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveFinite( ulpdiff( PINF, 5.0 ) ), true, 'returns expected value' ); + + t.strictEqual( isPositiveFinite( ulpdiff( 5.0, NINF ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveFinite( ulpdiff( NINF, 5.0 ) ), true, 'returns expected value' ); + + t.strictEqual( isPositiveFinite( ulpdiff( PINF, NINF ) ), true, 'returns expected value' ); + t.strictEqual( isPositiveFinite( ulpdiff( NINF, PINF ) ), true, 'returns expected value' ); + + t.strictEqual( ulpdiff( MAX_VALUE, PINF ), 1.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -MAX_VALUE, NINF ), 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles subnormal numbers', function test( t ) { + t.strictEqual( ulpdiff( SMALLEST_SUBNORMAL, 0.0 ), 1.0, 'returns expected value' ); + t.strictEqual( ulpdiff( 0.0, SMALLEST_SUBNORMAL ), 1.0, 'returns expected value' ); + + t.strictEqual( ulpdiff( SMALLEST_SUBNORMAL, -SMALLEST_SUBNORMAL ), 2.0, 'returns expected value' ); + t.strictEqual( ulpdiff( -SMALLEST_SUBNORMAL, SMALLEST_SUBNORMAL ), 2.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the function returns `NaN`', function test( t ) { + t.strictEqual( isnan( ulpdiff( NaN, 5.0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( ulpdiff( NaN, PINF ) ), true, 'returns expected value' ); + t.strictEqual( isnan( ulpdiff( NaN, NINF ) ), true, 'returns expected value' ); + t.strictEqual( isnan( ulpdiff( NaN, SMALLEST_SUBNORMAL ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( ulpdiff( 5.0, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( ulpdiff( PINF, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( ulpdiff( NINF, NaN ) ), true, 'returns expected value' ); + t.strictEqual( isnan( ulpdiff( SMALLEST_SUBNORMAL, NaN ) ), true, 'returns expected value' ); + + t.strictEqual( isnan( ulpdiff( NaN, NaN ) ), true, 'returns expected value' ); + + t.end(); +});