Skip to content
Draft
Show file tree
Hide file tree
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
15 changes: 4 additions & 11 deletions lib/node_modules/@stdlib/math/base/special/hypotf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );


Expand Down Expand Up @@ -123,26 +122,20 @@ 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;
expected = data.expected;

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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' );


Expand Down Expand Up @@ -132,33 +131,25 @@ 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;
expected = data.expected;

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 );
Expand All @@ -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();
});
Expand Down