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
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

var tape = require( 'tape' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var absf = require( '@stdlib/math/base/special/absf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var binomcoeff = require( './../lib' );

Expand Down Expand Up @@ -54,8 +53,6 @@ tape( 'the function returns `NaN` if provided `NaN` for any parameter', function

tape( 'the function evaluates the binomial coefficient for integers `n` and `k`', function test( t ) {
var expected;
var delta;
var tol;
var n;
var k;
var v;
Expand All @@ -71,11 +68,8 @@ tape( 'the function evaluates the binomial coefficient for integers `n` and `k`'
t.strictEqual( v, expected[ i ], 'returns expected value' );
continue;
}
delta = absf( v - expected[ i ] );

// NOTE: Exact comparison fails for large values due to single-precision floating-point rounding errors when intermediate results exceed the maximum safe integer for a 32-bit float.
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.

You need to preserve this comment.

tol = 1.25 * EPS * absf( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. n: ' + n[ i ] + '. k: ' + k[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
t.strictEqual( isAlmostSameValue( v, expected[ i ], 2 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -93,7 +87,7 @@ tape( 'the function evaluates the binomial coefficient for integers `n` and `k`
for ( i = 0; i < n.length; i++ ) {
v = binomcoeff( n[ i ], k[ i ] );
expected[ i ] = float64ToFloat32( expected[ i ] );
t.strictEqual( v, expected[ i ], 'returns expected value. actual: '+v+'. expected: '+expected[i]+'. n: '+n[i]+'. k: '+k[i]+'.' );
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.

Why did you replace a strictEqual check? If the results are exactly equal already, we don't need to migrate to isAlmostSameValue.

t.strictEqual( v, expected[ i ], 'returns expected value' );
}
t.end();
});
Expand Down