From 946d119437eebe337e8c5ae6315de164b61d547f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 10 Jun 2026 02:30:25 -0500 Subject: [PATCH] test: migrate `math/base/special/pow` to ULP-based testing --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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 --- --- .../math/base/special/pow/test/test.native.js | 89 +++++-------------- 1 file changed, 21 insertions(+), 68 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js index 9155b7ffc71d..77da65e94d9b 100644 --- a/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/pow/test/test.native.js @@ -33,6 +33,7 @@ var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -221,8 +222,6 @@ tape( 'the function evaluates the exponential function (`x ~ 1`, `y` large)', op tape( 'the function evaluates the exponential function (`x ~ 1`, `y` huge)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -232,14 +231,9 @@ tape( 'the function evaluates the exponential function (`x ~ 1`, `y` huge)', opt expected = baseNearUnityHuge.expected; for ( i = 0; i < x.length; i++ ) { actual = pow( x[i], y[i] ); - if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); - } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -420,8 +414,6 @@ tape( 'the function evaluates the exponential function (near underflow)', opts, tape( 'the function evaluates the exponential function (small `x`, large `y`)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -433,13 +425,9 @@ tape( 'the function evaluates the exponential function (small `x`, large `y`)', actual = pow( x[i], y[i] ); if ( expected[i] === 5.0e-324 ) { t.strictEqual( actual === expected[i] || actual === 0.0, true, 'pow('+x[i]+','+y[i]+') returns 5e-324 or 0' ); - } else if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } } t.end(); @@ -465,8 +453,6 @@ tape( 'the function evaluates the exponential function (large `x`, small `y`)', tape( 'the function evaluates the exponential function (small `x`, small `y`)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -476,14 +462,9 @@ tape( 'the function evaluates the exponential function (small `x`, small `y`)', expected = smallSmall.expected; for ( i = 0; i < x.length; i++ ) { actual = pow( x[i], y[i] ); - if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); - } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -491,8 +472,6 @@ tape( 'the function evaluates the exponential function (small `x`, small `y`)', tape( 'the function evaluates the exponential function (decimal `x`, decimal `y`)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -502,14 +481,9 @@ tape( 'the function evaluates the exponential function (decimal `x`, decimal `y` expected = decimalDecimal.expected; for ( i = 0; i < x.length; i++ ) { actual = pow( x[i], y[i] ); - if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); - } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -517,8 +491,6 @@ tape( 'the function evaluates the exponential function (decimal `x`, decimal `y` tape( 'the function evaluates the exponential function (decimal `x`, integer `y`)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -528,14 +500,9 @@ tape( 'the function evaluates the exponential function (decimal `x`, integer `y` expected = decimalInteger.expected; for ( i = 0; i < x.length; i++ ) { actual = pow( x[i], y[i] ); - if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); - } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -543,8 +510,6 @@ tape( 'the function evaluates the exponential function (decimal `x`, integer `y` tape( 'the function evaluates the exponential function (integer `x`, decimal `y`)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -554,14 +519,9 @@ tape( 'the function evaluates the exponential function (integer `x`, decimal `y` expected = integerDecimal.expected; for ( i = 0; i < x.length; i++ ) { actual = pow( x[i], y[i] ); - if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); - } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -569,8 +529,6 @@ tape( 'the function evaluates the exponential function (integer `x`, decimal `y` tape( 'the function evaluates the exponential function (integer `x`, integer `y`)', opts, function test( t ) { var expected; var actual; - var delta; - var tol; var x; var y; var i; @@ -580,14 +538,9 @@ tape( 'the function evaluates the exponential function (integer `x`, integer `y` expected = integerInteger.expected; for ( i = 0; i < x.length; i++ ) { actual = pow( x[i], y[i] ); - if ( actual === expected[i] ) { - t.strictEqual( actual, expected[i], 'pow('+x[i]+','+y[i]+') returns '+expected[i] ); - } else { - // NOTE: the results may differ slightly from the reference and JavaScript implementations due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 - delta = abs( actual - expected[i] ); - tol = EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. pow('+x[i]+','+y[i]+'). Expected: '+expected[i]+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + + // NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205 + t.strictEqual( isAlmostSameValue( actual, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); });