Skip to content

Commit f684340

Browse files
gunjjoshikgryte
andauthored
feat: add math/base/special/asindf
PR-URL: #2132 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 64d9f19 commit f684340

File tree

28 files changed

+1974
-0
lines changed

28 files changed

+1974
-0
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# asindf
22+
23+
> Compute the [arcsine][arcsine] (in degrees) of a single-precision floating-point number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var asindf = require( '@stdlib/math/base/special/asindf' );
31+
```
32+
33+
#### asindf( x )
34+
35+
Computes the [arcsine][arcsine] (in degrees) of a single-precision floating-point number.
36+
37+
```javascript
38+
var sqrtf = require( '@stdlib/math/base/special/sqrtf' );
39+
40+
var v = asindf( 0.0 );
41+
// returns 0.0
42+
43+
v = asindf( 0.5 );
44+
// returns ~30.0
45+
46+
v = asindf( sqrtf( 2.0 ) / 2.0 );
47+
// returns ~45.0
48+
49+
v = asindf( sqrtf( 3.0 ) / 2.0 );
50+
// returns ~60.0
51+
52+
v = asindf( NaN );
53+
// returns NaN
54+
```
55+
56+
The domain of `x` is restricted to `[-1,1]`. If `|x| > 1`, the function returns `NaN`.
57+
58+
```javascript
59+
var v = asindf( -3.14 );
60+
// returns NaN
61+
```
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<section class="examples">
68+
69+
## Examples
70+
71+
<!-- eslint no-undef: "error" -->
72+
73+
```javascript
74+
var linspace = require( '@stdlib/array/base/linspace' );
75+
var asindf = require( '@stdlib/math/base/special/asindf' );
76+
77+
var x = linspace( -1.0, 1.0, 100 );
78+
79+
var i;
80+
for ( i = 0; i < x.length; i++ ) {
81+
console.log( asindf( x[ i ] ) );
82+
}
83+
```
84+
85+
</section>
86+
87+
<!-- /.examples -->
88+
89+
<!-- C interface documentation. -->
90+
91+
* * *
92+
93+
<section class="c">
94+
95+
## C APIs
96+
97+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
98+
99+
<section class="intro">
100+
101+
</section>
102+
103+
<!-- /.intro -->
104+
105+
<!-- C usage documentation. -->
106+
107+
<section class="usage">
108+
109+
### Usage
110+
111+
```c
112+
#include "stdlib/math/base/special/asindf.h"
113+
```
114+
115+
#### stdlib_base_asindf( x )
116+
117+
Computes the [arcsine][arcsine] (in degrees) of a single-precision floating-point number.
118+
119+
```c
120+
float out = stdlib_base_asindf( 0.0f );
121+
// returns 0.0f
122+
123+
out = stdlib_base_asindf( 0.5f );
124+
// returns ~30.0f
125+
```
126+
127+
The function accepts the following arguments:
128+
129+
- **x**: `[in] float` input value.
130+
131+
```c
132+
float stdlib_base_asindf( const float x );
133+
```
134+
135+
</section>
136+
137+
<!-- /.usage -->
138+
139+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
140+
141+
<section class="notes">
142+
143+
</section>
144+
145+
<!-- /.notes -->
146+
147+
<!-- C API usage examples. -->
148+
149+
<section class="examples">
150+
151+
### Examples
152+
153+
```c
154+
#include "stdlib/math/base/special/asindf.h"
155+
#include <stdio.h>
156+
157+
int main( void ) {
158+
const float x[] = { 1.0f, 0.45f, -0.89f, 0.33f, -0.78f, -0.22f, 0.66f, 0.11f, -0.55f, 0.0f };
159+
160+
float v;
161+
int i;
162+
for ( i = 0; i < 10; i++ ) {
163+
v = stdlib_base_asindf( x[ i ] );
164+
printf( "asind(%f) = %f\n", x[ i ], v );
165+
}
166+
}
167+
```
168+
169+
</section>
170+
171+
<!-- /.examples -->
172+
173+
</section>
174+
175+
<!-- /.c -->
176+
177+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
178+
179+
<section class="related">
180+
181+
</section>
182+
183+
<!-- /.related -->
184+
185+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
186+
187+
<section class="links">
188+
189+
[arcsine]: https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
190+
191+
<!-- <related-links> -->
192+
193+
<!-- </related-links> -->
194+
195+
</section>
196+
197+
<!-- /.links -->
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var randu = require( '@stdlib/random/base/randu' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pkg = require( './../package.json' ).name;
27+
var asindf = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var y;
35+
var i;
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
x = ( randu() * 2.0 ) - 1.0;
40+
y = asindf( x );
41+
if ( isnanf( y ) ) {
42+
b.fail( 'should not return NaN' );
43+
}
44+
}
45+
b.toc();
46+
if ( isnanf( y ) ) {
47+
b.fail( 'should not return NaN' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var asindf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( asindf instanceof Error )
36+
};
37+
38+
39+
// MAIN //
40+
41+
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var x;
43+
var y;
44+
var i;
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
x = ( randu() * 2.0 ) - 1.0;
49+
y = asindf( x );
50+
if ( isnanf( y ) ) {
51+
b.fail( 'should not return NaN' );
52+
}
53+
}
54+
b.toc();
55+
if ( isnanf( y ) ) {
56+
b.fail( 'should not return NaN' );
57+
}
58+
b.pass( 'benchmark finished' );
59+
b.end();
60+
});

0 commit comments

Comments
 (0)