From 975b3781bc4cf362a00a4f2fb7407c883e1fa036 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Aug 2026 09:15:42 +0000 Subject: [PATCH 1/2] test: migrate math/base/special/roundn to ULP-based assertions Resolves a part of #11352. Replaces the manual `delta <= tol` relative-tolerance check in the subnormal-rounding test with `@stdlib/assert/is-almost-same-value` using a ULP budget of 1, mirroring the migrations already merged for the sibling `truncn` and `floorb` packages. --- .../math/base/special/roundn/test/test.js | 18 +++++++----------- .../base/special/roundn/test/test.native.js | 14 +++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js index e498b6612ac5..0745faf7d3b4 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js @@ -24,17 +24,21 @@ var tape = require( 'tape' ); var PI = require( '@stdlib/constants/float64/pi' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var randu = require( '@stdlib/random/base/randu' ); var round = require( '@stdlib/math/base/special/round' ); var pow = require( '@stdlib/math/base/special/pow' ); -var abs = require( '@stdlib/math/base/special/abs' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var roundn = require( './../lib' ); +// VARIABLES // + +var ULP = 1; + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -197,8 +201,6 @@ tape( 'if `n > 308`, the function returns `+-0` (sign preserving)', function tes tape( 'the function supports rounding very small numbers (including subnormals)', function test( t ) { var expected; - var delta; - var tol; var x; var n; var v; @@ -232,13 +234,7 @@ tape( 'the function supports rounding very small numbers (including subnormals)' for ( i = 0; i < n.length; i++ ) { v = roundn( x, n[i] ); - if ( v === expected[i] ) { - t.strictEqual( v, expected[ i ], 'returns '+expected[i]+' when provided x='+x+' and n='+n[i]+'.' ); - } else { - delta = abs( v - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'x: '+x+'. n: '+n[i]+'. v: '+v+'. expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol ); - } + t.strictEqual( isAlmostSameValue( v, expected[ i ], ULP ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js index 04d5b02988b9..980707c7155e 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js @@ -25,14 +25,13 @@ var tape = require( 'tape' ); var PI = require( '@stdlib/constants/float64/pi' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var randu = require( '@stdlib/random/base/randu' ); var round = require( '@stdlib/math/base/special/round' ); var pow = require( '@stdlib/math/base/special/pow' ); -var abs = require( '@stdlib/math/base/special/abs' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -42,6 +41,7 @@ var roundn = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( roundn instanceof Error ) }; +var ULP = 1; // TESTS // @@ -188,8 +188,6 @@ tape( 'if `n > 308`, the function returns `+-0` (sign preserving)', opts, functi tape( 'the function supports rounding very small numbers (including subnormals)', opts, function test( t ) { var expected; - var delta; - var tol; var x; var n; var v; @@ -223,13 +221,7 @@ tape( 'the function supports rounding very small numbers (including subnormals)' for ( i = 0; i < n.length; i++ ) { v = roundn( x, n[i] ); - if ( v === expected[i] ) { - t.strictEqual( v, expected[ i ], 'returns '+expected[i]+' when provided x='+x+' and n='+n[i]+'.' ); - } else { - delta = abs( v - expected[i] ); - tol = EPS * abs( expected[i] ); - t.strictEqual( delta <= tol, true, 'x: '+x+'. n: '+n[i]+'. v: '+v+'. expected: '+expected[i]+'. delta: '+delta+'. tol: '+tol ); - } + t.strictEqual( isAlmostSameValue( v, expected[ i ], ULP ), true, 'returns expected value' ); } t.end(); }); From afdaca56b90e2b157bea0f62d68e5e71aeed6cce Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Aug 2026 03:02:28 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/math/base/special/roundn/test/test.js | 7 +------ .../@stdlib/math/base/special/roundn/test/test.native.js | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js index 0745faf7d3b4..2ee22ced0f18 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.js @@ -34,11 +34,6 @@ var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var roundn = require( './../lib' ); -// VARIABLES // - -var ULP = 1; - - // TESTS // tape( 'main export is a function', function test( t ) { @@ -234,7 +229,7 @@ tape( 'the function supports rounding very small numbers (including subnormals)' for ( i = 0; i < n.length; i++ ) { v = roundn( x, n[i] ); - t.strictEqual( isAlmostSameValue( v, expected[ i ], ULP ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js index 980707c7155e..309c78c39f39 100644 --- a/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/roundn/test/test.native.js @@ -41,7 +41,6 @@ var roundn = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( roundn instanceof Error ) }; -var ULP = 1; // TESTS // @@ -221,7 +220,7 @@ tape( 'the function supports rounding very small numbers (including subnormals)' for ( i = 0; i < n.length; i++ ) { v = roundn( x, n[i] ); - t.strictEqual( isAlmostSameValue( v, expected[ i ], ULP ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValue( v, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); });