From e45218f7fe6e097e591d9a25a3d9fbee413fda8d Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Wed, 10 Jun 2026 02:31:40 -0500 Subject: [PATCH] test: migrate `math/base/special/hypotf` 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/hypotf/test/test.js | 15 ++++--------- .../base/special/hypotf/test/test.native.js | 21 +++++-------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.js b/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.js index f533ebc6e8c0..581a5828807f 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.js @@ -24,12 +24,11 @@ var tape = require( 'tape' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var absf = require( '@stdlib/math/base/special/absf' ); var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); var pow = require( '@stdlib/math/base/special/pow' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var hypotf = require( './../lib' ); @@ -123,12 +122,11 @@ tape( 'the function returns `+0` if both arguments are `+-0`', function test( t tape( 'the function computes the hypotenuse', function test( t ) { var expected; - var delta; - var tol; var h; var x; var y; var i; + var e; x = data.x; y = data.y; @@ -136,13 +134,8 @@ tape( 'the function computes the hypotenuse', function test( t ) { for ( i = 0; i < x.length; i++ ) { h = hypotf( x[ i ], y[ i ] ); - if ( h === expected[ i ] ) { - t.ok( true, 'x: '+x[i]+'. y: '+y[i]+'. h: '+h+'. Expected: '+expected[i]+'.' ); - } else { - delta = absf( h - expected[ i ] ); - tol = 2.0 * EPS * absf( expected[ i ] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y[i]+'. h: '+h+'. Expected: '+expected[i]+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + e = float64ToFloat32( expected[ i ] ); + t.strictEqual( isAlmostSameValue( h, e, 2 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.native.js index 30c4318a7f1f..3c9a95255935 100644 --- a/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/hypotf/test/test.native.js @@ -25,12 +25,11 @@ var tape = require( 'tape' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); -var EPS = require( '@stdlib/constants/float32/eps' ); -var absf = require( '@stdlib/math/base/special/absf' ); var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); var pow = require( '@stdlib/math/base/special/pow' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -132,12 +131,11 @@ tape( 'the function returns `+0` if both arguments are `+-0`', opts, function te tape( 'the function computes the hypotenuse', opts, function test( t ) { var expected; - var delta; - var tol; var h; var x; var y; var i; + var e; x = data.x; y = data.y; @@ -145,20 +143,13 @@ tape( 'the function computes the hypotenuse', opts, function test( t ) { for ( i = 0; i < x.length; i++ ) { h = hypotf( x[ i ], y[ i ] ); - if ( h === expected[ i ] ) { - t.ok( true, 'x: '+x[i]+'. y: '+y[i]+'. h: '+h+'. Expected: '+expected[i]+'.' ); - } else { - delta = absf( h - expected[ i ] ); - tol = 2.0 * EPS * absf( expected[ i ] ); - t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y[i]+'. h: '+h+'. Expected: '+expected[i]+'. Delta: '+delta+'. Tol: '+tol+'.' ); - } + e = float64ToFloat32( expected[ i ] ); + t.strictEqual( isAlmostSameValue( h, e, 2 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the hypotenuse (canonical inputs)', opts, function test( t ) { - var delta; - var tol; var h; h = hypotf( 3.0, 4.0 ); @@ -169,9 +160,7 @@ tape( 'the function computes the hypotenuse (canonical inputs)', opts, function // 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 h = hypotf( 5.0, 12.0 ); - delta = absf( h - 13.0 ); - tol = EPS * absf( 13.0 ); - t.strictEqual( delta <= tol, true, 'within tolerance. h: '+h+'. Expected: 13.0. Delta: '+delta+'. Tol: '+tol+'.' ); + t.strictEqual( isAlmostSameValue( h, 13.0, 1 ), true, 'returns expected value' ); t.end(); });