Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 15 additions & 128 deletions lib/node_modules/@stdlib/math/base/special/cbrtf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' );
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
var cbrtf = require( './../lib' );


Expand Down Expand Up @@ -59,8 +58,6 @@ tape( 'main export is a function', function test( t ) {

tape( 'the function evaluates the cubic root of `x` on the interval `[-50,-500]', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -69,21 +66,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-50,-500]'
x = veryLargeNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MANDEep22332 You're using a maxULPs argument of 3 here and below, but previously tests passed with just EPS and the JS implementation uses 1. Is there a reason for the discrepancy?

}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[50,500]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -92,21 +81,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[50,500]`',
x = veryLargePositive.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-50]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -115,21 +96,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-50]`'
x = largeNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[20,50]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -138,21 +111,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[20,50]`',
x = largePositive.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-3]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -161,21 +126,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-20,-3]`',
x = mediumNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[3,20]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -184,21 +141,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[3,20]`', f
x = mediumPositive.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[-3,-0.8]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -207,21 +156,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-3,-0.8]`'
x = smallNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[0.8,3]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -230,21 +171,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[0.8,3]`',
x = smallPositive.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates cubic root of `x` on the interval `[-0.8,0.8]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -253,21 +186,13 @@ tape( 'the function evaluates cubic root of `x` on the interval `[-0.8,0.8]`', f
x = smaller.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[-1e-300,-1e-308]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -276,21 +201,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[-1e-300,-1
x = tinyNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` on the interval `[1e-300,1e-308]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -299,21 +216,13 @@ tape( 'the function evaluates the cubic root of `x` on the interval `[1e-300,1e-
x = tinyPositive.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of subnormal `x`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -322,21 +231,13 @@ tape( 'the function evaluates the cubic root of subnormal `x`', function test( t
x = subnormal.x;
for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` (huge negative)', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -346,21 +247,13 @@ tape( 'the function evaluates the cubic root of `x` (huge negative)', function t

for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the cubic root of `x` (huge positive)', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -370,13 +263,7 @@ tape( 'the function evaluates the cubic root of `x` (huge positive)', function t

for ( i = 0; i < x.length; i++ ) {
y = cbrtf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValuef( y, expected[ i ], 3 ), true, 'returns expected value' );
}
t.end();
});
Expand Down
Loading