From dfeefaa7ed59c86c7f489fb36e06735ec05aa1c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 8 Aug 2026 14:19:21 +0000 Subject: [PATCH] test: migrate `math/base/special/polygamma` to ULP-based assertions Ref: https://github.com/stdlib-js/stdlib/issues/11352 --- .../math/base/special/polygamma/test/test.js | 67 +++---------------- 1 file changed, 9 insertions(+), 58 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/polygamma/test/test.js b/lib/node_modules/@stdlib/math/base/special/polygamma/test/test.js index 1f8229213982..f57e272c6978 100644 --- a/lib/node_modules/@stdlib/math/base/special/polygamma/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/polygamma/test/test.js @@ -21,14 +21,13 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var factorial = require( '@stdlib/math/base/special/factorial' ); var incrspace = require( '@stdlib/array/base/incrspace' ); var isnan = require( '@stdlib/assert/is-nan' ); var ldexp = require( '@stdlib/math/base/special/ldexp' ); var zeta = require( '@stdlib/math/base/special/riemann-zeta' ); -var abs = require( '@stdlib/math/base/special/abs' ); var PINF = require( '@stdlib/constants/float64/pinf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var polygamma = require( './../lib' ); @@ -82,8 +81,6 @@ tape( 'if provided an odd negative integer for `x`, the function returns positiv tape( 'the function evaluates the polygamma function for small positive numbers', function test( t ) { var expected; - var delta; - var tol; var n; var x; var y; @@ -94,21 +91,13 @@ tape( 'the function evaluates the polygamma function for small positive numbers' expected = smallPositive.y; for ( i = 0; i < x.length; i++ ) { y = polygamma(n[i], x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 20.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 3 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the polygamma function for positive numbers', function test( t ) { var expected; - var delta; - var tol; var n; var x; var y; @@ -119,21 +108,13 @@ tape( 'the function evaluates the polygamma function for positive numbers', func expected = positive.y; for ( i = 0; i < x.length; i++ ) { y = polygamma(n[i], x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 20.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 15 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the polygamma function for negative numbers', function test( t ) { var expected; - var delta; - var tol; var n; var x; var y; @@ -144,21 +125,13 @@ tape( 'the function evaluates the polygamma function for negative numbers', func expected = negative.y; for ( i = 0; i < x.length; i++ ) { y = polygamma( n[i], x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 2300.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2858 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the polygamma function for large positive numbers', function test( t ) { var expected; - var delta; - var tol; var n; var x; var y; @@ -169,21 +142,13 @@ tape( 'the function evaluates the polygamma function for large positive numbers' expected = largePositive.y; for ( i = 0; i < x.length; i++ ) { y = polygamma(n[i], x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 20.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 18 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the polygamma function for large negative numbers', function test( t ) { var expected; - var delta; - var tol; var n; var x; var y; @@ -194,23 +159,15 @@ tape( 'the function evaluates the polygamma function for large negative numbers' expected = largeNegative.y; for ( i = 0; i < x.length; i++ ) { y = polygamma( n[i], x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - - // The large discrepancies for a few input values seem to be mostly due to a slight difference in the calculation of `cospi`, which is used in `polycotpi.js`. For example, for `x = 128.69279279279279`, our `cospi` function returns `-0.5693183042040957`, whereas Boost returns `-0.56931830420405894`. These differences are then magnified as the result is used as the value at which polynomials are evaluated. - tol = 2200.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + + // The large discrepancies for a few input values seem to be mostly due to a slight difference in the calculation of `cospi`, which is used in `polycotpi.js`. For example, for `x = 128.69279279279279`, our `cospi` function returns `-0.5693183042040957`, whereas Boost returns `-0.56931830420405894`. These differences are then magnified as the result is used as the value at which polynomials are evaluated. + t.strictEqual( isAlmostSameValue( y, expected[ i ], 2773 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function evaluates the polygamma function for huge positive numbers', function test( t ) { var expected; - var delta; - var tol; var n; var x; var y; @@ -221,13 +178,7 @@ tape( 'the function evaluates the polygamma function for huge positive numbers', expected = hugePositive.y; for ( i = 0; i < x.length; i++ ) { y = polygamma(n[i], x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ i ], 'n: '+n[i]+'. x: '+x[i]+'. E: '+expected[i] ); - } else { - delta = abs( y - expected[i] ); - tol = 1.0 * EPS * abs( expected[i] ); - t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' ); } t.end(); });