Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: decrease tolerance and clean-up math/base/special/asind #2138

Merged
merged 2 commits into from
Apr 7, 2024
Merged
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
5 changes: 3 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/asind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# asind

> Compute the [arcsine][arcsine] in degrees of a double-precision floating-point number.
> Compute the [arcsine][arcsine] (in degrees) of a double-precision floating-point number.

<section class="usage">

Expand All @@ -36,6 +36,7 @@ Computes the [arcsine][arcsine] (in degrees) of a double-precision floating-poin

```javascript
var sqrt = require( '@stdlib/math/base/special/sqrt' );

var v = asind( 0.0 );
// returns 0.0

Expand Down Expand Up @@ -154,7 +155,7 @@ double stdlib_base_asind( const double x );
#include <stdio.h>

int main( void ) {
const double x[] = { 1.0, 1.45, 1.89, 2.33, 2.78, 3.22, 3.66, 4.11, 4.55, 5.0 };
const double x[] = { 1.0, 0.45, -0.89, 0.33, -0.78, -0.22, 0.66, 0.11, -0.55, 0.0 };

double v;
int i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bench( pkg, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*2.0 ) - 1.0;
x = ( randu() * 2.0 ) - 1.0;
y = asind( x );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
--------
> var y = {{alias}}( 0.0 )
0.0
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/6.0 )
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}} / 6.0 )
~31.57
> y = {{alias}}( NaN )
NaN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
* // returns ~30.0
*
* @example
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
*
* var v = asindf( sqrt( 2.0 ) / 2.0 );
* // returns ~45.0
*
* @example
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
*
** var v = asindf( sqrt( 3.0 ) / 2.0 );
* // returns ~60.0
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <stdio.h>

int main( void ) {
const double x[] = { 1.0, 1.45, 1.89, 2.33, 2.78, 3.22, 3.66, 4.11, 4.55, 5.0 };
const double x[] = { 1.0, 0.45, -0.89, 0.33, -0.78, -0.22, 0.66, 0.11, -0.55, 0.0 };

double v;
int i;
Expand Down
5 changes: 3 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/asind/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @module @stdlib/math/base/special/asind
*
* @example
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
* var asind = require( '@stdlib/math/base/special/asind' );
*
* var v = asind( 0.0 );
Expand All @@ -32,10 +33,10 @@
* var v = asind( 0.5 );
* // returns ~30.0
*
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
* var v = asind( sqrt( 2.0 ) / 2.0 );
* // returns ~45.0
*
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
* var v = asind( sqrt( 3.0 ) / 2.0 );
* // returns ~60.0
*
* var v = asind( NaN );
Expand Down
11 changes: 7 additions & 4 deletions lib/node_modules/@stdlib/math/base/special/asind/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ var asin = require( '@stdlib/math/base/special/asin' );
* // returns ~30.0
*
* @example
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
*
* var v = asind( sqrt( 2.0 ) / 2.0 );
* // returns ~45.0
*
* @example
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
*
* var v = asind( sqrt( 3.0 ) / 2.0 );
* // returns ~60.0
*
* @example
* var v = asind( NaN );
* // returns NaN
*/
function asind( x ) {
var rad = asin( x );
return rad2deg( rad );
return rad2deg( asin( x ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var addon = require( './../src/addon.node' );
/**
* Computes the arcsine (in degrees) of a double-precision floating-point number.
*
* @private
* @param {number} x - input value
* @returns {number} arcsine (in degrees)
*
Expand All @@ -40,11 +41,15 @@ var addon = require( './../src/addon.node' );
* // returns ~30.0
*
* @example
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
*
* var v = asind( sqrt( 2.0 ) / 2.0 );
* // returns ~45.0
*
* @example
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
*
* var v = asind( sqrt( 3.0 ) / 2.0 );
* // returns ~60.0
*
* @example
Expand Down
7 changes: 2 additions & 5 deletions lib/node_modules/@stdlib/math/base/special/asind/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
* @return arcsine (in degrees)
*
* @example
* double v = stdlib_base_acotd( 0.0 );
* double v = stdlib_base_asind( 0.0 );
* // returns 0.0
*/
double stdlib_base_asind( const double x ) {
double rad;

rad = stdlib_base_asin( x );
return stdlib_base_rad2deg( rad );
return stdlib_base_rad2deg( stdlib_base_asin( x ) );
}
32 changes: 16 additions & 16 deletions lib/node_modules/@stdlib/math/base/special/asind/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var asind = require( './../lib' );
Expand Down Expand Up @@ -54,13 +54,13 @@ tape( 'the function computes the arcsine in degrees (negative values)', function
expected = negative.expected;

for ( i = 0; i < x.length; i++ ) {
y = asind( x[i] );
y = asind( x[ i ] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
delta = abs( y - expected[ i ] );
tol = 1.2 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
Expand All @@ -78,21 +78,21 @@ tape( 'the function computes the arcsine in degrees (positive values)', function
expected = positive.expected;

for ( i = 0; i < x.length; i++ ) {
y = asind( x[i] );
y = asind( x[ i ] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
delta = abs( y - expected[ i ] );
tol = 1.2 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
});

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
var v = asind( NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.equal( isnan( v ), true, 'returns expected value' );
t.end();
});

Expand All @@ -101,8 +101,8 @@ tape( 'the function returns `NaN` if provided a value less than `-1`', function
var i;

for ( i = 0; i < 1e3; i++ ) {
v = -(randu()*1.0e6) - (1.0-EPS);
t.equal( isnan( asind( v ) ), true, 'returns NaN when provided '+v );
v = uniform( -1.0e6, -1.0 - EPS );
t.equal( isnan( asind( v ) ), true, 'returns expected value when provided '+v );
}
t.end();
});
Expand All @@ -112,8 +112,8 @@ tape( 'the function returns `NaN` if provided a value greater than `+1`', functi
var i;

for ( i = 0; i < 1e3; i++ ) {
v = (randu()*1.0e6) + 1.0 + EPS;
t.equal( isnan( asind( v ) ), true, 'returns NaN when provided '+v );
v = uniform( 1.0 + EPS, 1.0e6 );
t.equal( isnan( asind( v ) ), true, 'returns expected value when provided '+v );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );
var tryRequire = require( '@stdlib/utils/try-require' );
Expand Down Expand Up @@ -63,13 +63,13 @@ tape( 'the function computes the arcsine in degrees (negative values)', opts, fu
expected = negative.expected;

for ( i = 0; i < x.length; i++ ) {
y = asind( x[i] );
y = asind( x[ i ] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
delta = abs( y - expected[ i ] );
tol = 1.2 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
Expand All @@ -87,13 +87,13 @@ tape( 'the function computes the arcsine in degrees (positive values)', opts, fu
expected = positive.expected;

for ( i = 0; i < x.length; i++ ) {
y = asind( x[i] );
y = asind( x[ i ] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
} else {
delta = abs( y - expected[i] );
tol = 1.4 * EPS * abs( expected[i] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
delta = abs( y - expected[ i ] );
tol = 1.2 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
}
}
t.end();
Expand All @@ -110,7 +110,7 @@ tape( 'the function returns `NaN` if provided a value less than `-1`', opts, fun
var i;

for ( i = 0; i < 1e3; i++ ) {
v = -(randu()*1.0e6) - (1.0-EPS);
v = uniform( -1.0e6, -1.0 - EPS );
t.equal( isnan( asind( v ) ), true, 'returns NaN when provided '+v );
}
t.end();
Expand All @@ -121,7 +121,7 @@ tape( 'the function returns `NaN` if provided a value greater than `+1`', opts,
var i;

for ( i = 0; i < 1e3; i++ ) {
v = (randu()*1.0e6) + 1.0 + EPS;
v = uniform( 1.0 + EPS, 1.0e6 );
t.equal( isnan( asind( v ) ), true, 'returns NaN when provided '+v );
}
t.end();
Expand Down
Loading