From c1b4a8965d9b9fe4a943c369bb0db342197ac17d Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Sun, 26 Jul 2026 01:20:33 +0530 Subject: [PATCH] test: migrate rsqrt to ULP-based testing --- .../math/base/special/rsqrt/test/test.js | 53 ++++--------------- .../base/special/rsqrt/test/test.native.js | 53 ++++--------------- 2 files changed, 20 insertions(+), 86 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.js b/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.js index a61bf743a32e..f19f4bd53c0c 100644 --- a/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.js @@ -21,12 +21,11 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var rsqrt = require( './../lib' ); @@ -52,8 +51,6 @@ tape( 'main export is a function', function test( t ) { tape( 'the function evaluates the reciprocal square root of `x` on the interval `[50,500]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -65,9 +62,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -75,8 +70,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[20,50]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -88,9 +81,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -98,8 +89,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[3,20]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -111,9 +100,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -121,8 +108,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[0.8,3]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -134,9 +119,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -144,8 +127,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[0.0,0.8]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -157,9 +138,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -167,8 +146,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[1e-300,1e-308]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -180,9 +157,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -190,8 +165,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of subnormal `x`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -203,9 +176,7 @@ tape( 'the function evaluates the reciprocal square root of subnormal `x`', func if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -213,8 +184,6 @@ tape( 'the function evaluates the reciprocal square root of subnormal `x`', func tape( 'the function evaluates the reciprocal square root of `x` (huge positive)', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -226,9 +195,7 @@ tape( 'the function evaluates the reciprocal square root of `x` (huge positive)' if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.native.js index 86d0ea3b9c80..5e59a5db6e0a 100644 --- a/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/rsqrt/test/test.native.js @@ -22,12 +22,11 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -61,8 +60,6 @@ tape( 'main export is a function', opts, function test( t ) { tape( 'the function evaluates the reciprocal square root of `x` on the interval `[50,500]`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -74,9 +71,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -84,8 +79,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[20,50]`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -97,9 +90,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -107,8 +98,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[3,20]`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -120,9 +109,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -130,8 +117,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[0.8,3]`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -143,9 +128,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -153,8 +136,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[0.0,0.8]`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -166,9 +147,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -176,8 +155,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of `x` on the interval `[1e-300,1e-308]`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -189,9 +166,7 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -199,8 +174,6 @@ tape( 'the function evaluates the reciprocal square root of `x` on the interval tape( 'the function evaluates the reciprocal square root of subnormal `x`', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -212,9 +185,7 @@ tape( 'the function evaluates the reciprocal square root of subnormal `x`', opts if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end(); @@ -222,8 +193,6 @@ tape( 'the function evaluates the reciprocal square root of subnormal `x`', opts tape( 'the function evaluates the reciprocal square root of `x` (huge positive)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -235,9 +204,7 @@ tape( 'the function evaluates the reciprocal square root of `x` (huge positive)' if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. Tolerance: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'returns expected value' ); } } t.end();