Skip to content

Commit 90177b2

Browse files
gunjjoshikgryte
andauthored
refactor: decrease tolerance and clean-up math/base/special/asind
PR-URL: #2138 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 4b7bda7 commit 90177b2

File tree

11 files changed

+60
-49
lines changed

11 files changed

+60
-49
lines changed

lib/node_modules/@stdlib/math/base/special/asind/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# asind
2222

23-
> Compute the [arcsine][arcsine] in degrees of a double-precision floating-point number.
23+
> Compute the [arcsine][arcsine] (in degrees) of a double-precision floating-point number.
2424
2525
<section class="usage">
2626

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

3737
```javascript
3838
var sqrt = require( '@stdlib/math/base/special/sqrt' );
39+
3940
var v = asind( 0.0 );
4041
// returns 0.0
4142

@@ -154,7 +155,7 @@ double stdlib_base_asind( const double x );
154155
#include <stdio.h>
155156
156157
int main( void ) {
157-
const double x[] = { 1.0, 1.45, 1.89, 2.33, 2.78, 3.22, 3.66, 4.11, 4.55, 5.0 };
158+
const double x[] = { 1.0, 0.45, -0.89, 0.33, -0.78, -0.22, 0.66, 0.11, -0.55, 0.0 };
158159
159160
double v;
160161
int i;

lib/node_modules/@stdlib/math/base/special/asind/benchmark/benchmark.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bench( pkg, function benchmark( b ) {
3636

3737
b.tic();
3838
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*2.0 ) - 1.0;
39+
x = ( randu() * 2.0 ) - 1.0;
4040
y = asind( x );
4141
if ( isnan( y ) ) {
4242
b.fail( 'should not return NaN' );

lib/node_modules/@stdlib/math/base/special/asind/docs/repl.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
--------
2020
> var y = {{alias}}( 0.0 )
2121
0.0
22-
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/6.0 )
22+
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}} / 6.0 )
2323
~31.57
2424
> y = {{alias}}( NaN )
2525
NaN

lib/node_modules/@stdlib/math/base/special/asind/docs/types/index.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@
3333
* // returns ~30.0
3434
*
3535
* @example
36-
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
36+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
37+
*
38+
* var v = asindf( sqrt( 2.0 ) / 2.0 );
3739
* // returns ~45.0
3840
*
3941
* @example
40-
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
42+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
43+
*
44+
** var v = asindf( sqrt( 3.0 ) / 2.0 );
4145
* // returns ~60.0
4246
*
4347
* @example

lib/node_modules/@stdlib/math/base/special/asind/examples/c/example.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <stdio.h>
2121

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

2525
double v;
2626
int i;

lib/node_modules/@stdlib/math/base/special/asind/lib/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @module @stdlib/math/base/special/asind
2525
*
2626
* @example
27+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
2728
* var asind = require( '@stdlib/math/base/special/asind' );
2829
*
2930
* var v = asind( 0.0 );
@@ -32,10 +33,10 @@
3233
* var v = asind( 0.5 );
3334
* // returns ~30.0
3435
*
35-
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
36+
* var v = asind( sqrt( 2.0 ) / 2.0 );
3637
* // returns ~45.0
3738
*
38-
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
39+
* var v = asind( sqrt( 3.0 ) / 2.0 );
3940
* // returns ~60.0
4041
*
4142
* var v = asind( NaN );

lib/node_modules/@stdlib/math/base/special/asind/lib/main.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,23 @@ var asin = require( '@stdlib/math/base/special/asin' );
4141
* // returns ~30.0
4242
*
4343
* @example
44-
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
44+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
45+
*
46+
* var v = asind( sqrt( 2.0 ) / 2.0 );
4547
* // returns ~45.0
4648
*
4749
* @example
48-
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
50+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
51+
*
52+
* var v = asind( sqrt( 3.0 ) / 2.0 );
4953
* // returns ~60.0
5054
*
5155
* @example
5256
* var v = asind( NaN );
5357
* // returns NaN
5458
*/
5559
function asind( x ) {
56-
var rad = asin( x );
57-
return rad2deg( rad );
60+
return rad2deg( asin( x ) );
5861
}
5962

6063

lib/node_modules/@stdlib/math/base/special/asind/lib/native.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var addon = require( './../src/addon.node' );
2828
/**
2929
* Computes the arcsine (in degrees) of a double-precision floating-point number.
3030
*
31+
* @private
3132
* @param {number} x - input value
3233
* @returns {number} arcsine (in degrees)
3334
*
@@ -40,11 +41,15 @@ var addon = require( './../src/addon.node' );
4041
* // returns ~30.0
4142
*
4243
* @example
43-
* var v = asind( Math.sqrt( 2.0 ) / 2.0 );
44+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
45+
*
46+
* var v = asind( sqrt( 2.0 ) / 2.0 );
4447
* // returns ~45.0
4548
*
4649
* @example
47-
* var v = asind( Math.sqrt( 3.0 ) / 2.0 );
50+
* var sqrt = require( '@stdlib/math/base/special/sqrt' );
51+
*
52+
* var v = asind( sqrt( 3.0 ) / 2.0 );
4853
* // returns ~60.0
4954
*
5055
* @example

lib/node_modules/@stdlib/math/base/special/asind/src/main.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
* @return arcsine (in degrees)
2828
*
2929
* @example
30-
* double v = stdlib_base_acotd( 0.0 );
30+
* double v = stdlib_base_asind( 0.0 );
3131
* // returns 0.0
3232
*/
3333
double stdlib_base_asind( const double x ) {
34-
double rad;
35-
36-
rad = stdlib_base_asin( x );
37-
return stdlib_base_rad2deg( rad );
34+
return stdlib_base_rad2deg( stdlib_base_asin( x ) );
3835
}

lib/node_modules/@stdlib/math/base/special/asind/test/test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
2626
var abs = require( '@stdlib/math/base/special/abs' );
2727
var EPS = require( '@stdlib/constants/float64/eps' );
2828
var asind = require( './../lib' );
@@ -54,13 +54,13 @@ tape( 'the function computes the arcsine in degrees (negative values)', function
5454
expected = negative.expected;
5555

5656
for ( i = 0; i < x.length; i++ ) {
57-
y = asind( x[i] );
57+
y = asind( x[ i ] );
5858
if ( y === expected[ i ] ) {
59-
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
59+
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
6060
} else {
61-
delta = abs( y - expected[i] );
62-
tol = 1.4 * EPS * abs( expected[i] );
63-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
61+
delta = abs( y - expected[ i ] );
62+
tol = 1.2 * EPS * abs( expected[ i ] );
63+
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
6464
}
6565
}
6666
t.end();
@@ -78,21 +78,21 @@ tape( 'the function computes the arcsine in degrees (positive values)', function
7878
expected = positive.expected;
7979

8080
for ( i = 0; i < x.length; i++ ) {
81-
y = asind( x[i] );
81+
y = asind( x[ i ] );
8282
if ( y === expected[ i ] ) {
83-
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
83+
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
8484
} else {
85-
delta = abs( y - expected[i] );
86-
tol = 1.4 * EPS * abs( expected[i] );
87-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
85+
delta = abs( y - expected[ i ] );
86+
tol = 1.2 * EPS * abs( expected[ i ] );
87+
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
8888
}
8989
}
9090
t.end();
9191
});
9292

9393
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
9494
var v = asind( NaN );
95-
t.equal( isnan( v ), true, 'returns NaN' );
95+
t.equal( isnan( v ), true, 'returns expected value' );
9696
t.end();
9797
});
9898

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

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

114114
for ( i = 0; i < 1e3; i++ ) {
115-
v = (randu()*1.0e6) + 1.0 + EPS;
116-
t.equal( isnan( asind( v ) ), true, 'returns NaN when provided '+v );
115+
v = uniform( 1.0 + EPS, 1.0e6 );
116+
t.equal( isnan( asind( v ) ), true, 'returns expected value when provided '+v );
117117
}
118118
t.end();
119119
});

lib/node_modules/@stdlib/math/base/special/asind/test/test.native.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var randu = require( '@stdlib/random/base/randu' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
2727
var abs = require( '@stdlib/math/base/special/abs' );
2828
var EPS = require( '@stdlib/constants/float64/eps' );
2929
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -63,13 +63,13 @@ tape( 'the function computes the arcsine in degrees (negative values)', opts, fu
6363
expected = negative.expected;
6464

6565
for ( i = 0; i < x.length; i++ ) {
66-
y = asind( x[i] );
66+
y = asind( x[ i ] );
6767
if ( y === expected[ i ] ) {
68-
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
68+
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
6969
} else {
70-
delta = abs( y - expected[i] );
71-
tol = 1.4 * EPS * abs( expected[i] );
72-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
70+
delta = abs( y - expected[ i ] );
71+
tol = 1.2 * EPS * abs( expected[ i ] );
72+
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
7373
}
7474
}
7575
t.end();
@@ -87,13 +87,13 @@ tape( 'the function computes the arcsine in degrees (positive values)', opts, fu
8787
expected = positive.expected;
8888

8989
for ( i = 0; i < x.length; i++ ) {
90-
y = asind( x[i] );
90+
y = asind( x[ i ] );
9191
if ( y === expected[ i ] ) {
92-
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
92+
t.equal( y, expected[ i ], 'x: '+x[ i ]+'. E: '+expected[ i ] );
9393
} else {
94-
delta = abs( y - expected[i] );
95-
tol = 1.4 * EPS * abs( expected[i] );
96-
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.' );
94+
delta = abs( y - expected[ i ] );
95+
tol = 1.2 * EPS * abs( expected[ i ] );
96+
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. y: '+y+'. E: '+expected[ i ]+'. tol: '+tol+'. Δ: '+delta+'.' );
9797
}
9898
}
9999
t.end();
@@ -110,7 +110,7 @@ tape( 'the function returns `NaN` if provided a value less than `-1`', opts, fun
110110
var i;
111111

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

123123
for ( i = 0; i < 1e3; i++ ) {
124-
v = (randu()*1.0e6) + 1.0 + EPS;
124+
v = uniform( 1.0 + EPS, 1.0e6 );
125125
t.equal( isnan( asind( v ) ), true, 'returns NaN when provided '+v );
126126
}
127127
t.end();

0 commit comments

Comments
 (0)