From 696ecbff72ba89c76ef92aaf65070b79a97df098 Mon Sep 17 00:00:00 2001 From: MANDEep22332 Date: Mon, 20 Apr 2026 09:49:52 +0000 Subject: [PATCH] ULP based Testing in the atan --- .../math/base/special/atan/test/test.js | 133 ++---------------- 1 file changed, 14 insertions(+), 119 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/atan/test/test.js b/lib/node_modules/@stdlib/math/base/special/atan/test/test.js index 795fef3a96a9..98522fe9e5d4 100644 --- a/lib/node_modules/@stdlib/math/base/special/atan/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/atan/test/test.js @@ -22,8 +22,7 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var EPS = require( '@stdlib/constants/float64/eps' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var PI = require( '@stdlib/constants/float64/pi' ); @@ -59,8 +58,6 @@ tape( 'main export is a function', function test( t ) { tape( 'the function computes the arctangent on the interval `[-1e-308,-1e-300]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -70,21 +67,13 @@ tape( 'the function computes the arctangent on the interval `[-1e-308,-1e-300]`' for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[1e-300,1e-308]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -94,21 +83,13 @@ tape( 'the function computes the arctangent on the interval `[1e-300,1e-308]`', for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[-0.8,0.8]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -118,21 +99,13 @@ tape( 'the function computes the arctangent on the interval `[-0.8,0.8]`', funct for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[-1.0,-0.8]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -142,21 +115,13 @@ tape( 'the function computes the arctangent on the interval `[-1.0,-0.8]`', func for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[0.8,1.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -166,21 +131,13 @@ tape( 'the function computes the arctangent on the interval `[0.8,1.0]`', functi for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[-3.0,-1.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -190,21 +147,13 @@ tape( 'the function computes the arctangent on the interval `[-3.0,-1.0]`', func for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[1.0,3.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -214,21 +163,13 @@ tape( 'the function computes the arctangent on the interval `[1.0,3.0]`', functi for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[3.0,100.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -238,21 +179,13 @@ tape( 'the function computes the arctangent on the interval `[3.0,100.0]`', func for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[-100.0,-3.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -262,21 +195,13 @@ tape( 'the function computes the arctangent on the interval `[-100.0,-3.0]`', fu for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[100.0,1000.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -286,21 +211,13 @@ tape( 'the function computes the arctangent on the interval `[100.0,1000.0]`', f for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[-1000.0,-100.0]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -310,21 +227,13 @@ tape( 'the function computes the arctangent on the interval `[-1000.0,-100.0]`', for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[-1e200,-1e208]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -334,21 +243,13 @@ tape( 'the function computes the arctangent on the interval `[-1e200,-1e208]`', for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); tape( 'the function computes the arctangent on the interval `[1e300,1e308]`', function test( t ) { var expected; - var delta; - var tol; var x; var y; var i; @@ -358,13 +259,7 @@ tape( 'the function computes the arctangent on the interval `[1e300,1e308]`', fu for ( i = 0; i < x.length; i++ ) { y = atan( x[i] ); - if ( y === expected[ i ] ) { - t.strictEqual( y, expected[ 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. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' ); - } + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); } t.end(); });