Skip to content

Commit 4bddc16

Browse files
authored
feat: add math/base/special/aversinf
PR-URL: #2852 Ref: #649 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent ff629c7 commit 4bddc16

File tree

28 files changed

+1967
-0
lines changed

28 files changed

+1967
-0
lines changed
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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+
# Arcversinef
22+
23+
> Compute the [inverse versed sine][inverse-versed-sine] of a single-precision floating-point number (in radians).
24+
25+
<section class="intro">
26+
27+
The [inverse versed sine][inverse-versed-sine] is defined as
28+
29+
<!-- <equation class="equation" label="eq:arcversine" align="center" raw="\operatorname{aversinf}(\theta) = \arccos(1-\theta)" alt="Inverse versed sine."> -->
30+
31+
```math
32+
\mathop{\mathrm{aversinf}}(\theta) = \arccos(1-\theta)
33+
```
34+
35+
<!-- </equation> -->
36+
37+
</section>
38+
39+
<!-- /.intro -->
40+
41+
<section class="usage">
42+
43+
## Usage
44+
45+
```javascript
46+
var aversinf = require( '@stdlib/math/base/special/aversinf' );
47+
```
48+
49+
#### aversinf( x )
50+
51+
Computes the [inverse versed sine][inverse-versed-sine] of a single-precision floating-point number (in radians).
52+
53+
```javascript
54+
var v = aversinf( 0.0 );
55+
// returns 0.0
56+
57+
v = aversinf( 3.141592653589793 / 2.0 );
58+
// returns ~2.1783
59+
60+
v = aversinf( 3.141592653589793 / 6.0 );
61+
// returns ~1.0742
62+
```
63+
64+
If `x < 0`, `x > 2`, or `x` is `NaN`, the function returns `NaN`.
65+
66+
```javascript
67+
var v = aversinf( -1.0 );
68+
// returns NaN
69+
70+
v = aversinf( 3.14 );
71+
// returns NaN
72+
73+
v = aversinf( NaN );
74+
// returns NaN
75+
```
76+
77+
</section>
78+
79+
<!-- /.usage -->
80+
81+
<section class="examples">
82+
83+
## Examples
84+
85+
<!-- eslint no-undef: "error" -->
86+
87+
```javascript
88+
var linspace = require( '@stdlib/array/base/linspace' );
89+
var aversinf = require( '@stdlib/math/base/special/aversinf' );
90+
91+
var x = linspace( 0.0, 2.0, 100 );
92+
93+
var i;
94+
for ( i = 0; i < x.length; i++ ) {
95+
console.log( aversinf( x[ i ] ) );
96+
}
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- C interface documentation. -->
104+
105+
* * *
106+
107+
<section class="c">
108+
109+
## C APIs
110+
111+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
112+
113+
<section class="intro">
114+
115+
</section>
116+
117+
<!-- /.intro -->
118+
119+
<!-- C usage documentation. -->
120+
121+
<section class="usage">
122+
123+
### Usage
124+
125+
```c
126+
#include "stdlib/math/base/special/aversinf.h"
127+
```
128+
129+
#### stdlib_base_aversinf( x )
130+
131+
Compute the [inverse versed sine][inverse-versed-sine] of a single-precision floating-point number (in radians).
132+
133+
```c
134+
float out = stdlib_base_aversinf( 3.141592653589793f / 2.0f );
135+
// returns ~2.1783f
136+
```
137+
138+
If `x < 0`, `x > 2`, or `x` is `NaN`, the function returns `NaN`.
139+
140+
```c
141+
float out = stdlib_base_aversinf( 3.141592653589793f );
142+
// returns NaN
143+
```
144+
145+
The function accepts the following arguments:
146+
147+
- **x**: `[in] float` input value.
148+
149+
```c
150+
float stdlib_base_aversinf( const float x );
151+
```
152+
153+
</section>
154+
155+
<!-- /.usage -->
156+
157+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
158+
159+
<section class="notes">
160+
161+
</section>
162+
163+
<!-- /.notes -->
164+
165+
<!-- C API usage examples. -->
166+
167+
<section class="examples">
168+
169+
### Examples
170+
171+
```c
172+
#include "stdlib/math/base/special/aversinf.h"
173+
#include <stdio.h>
174+
175+
int main( void ) {
176+
const float x[] = { -2.5f, -2.0f, -1.5f, -1.0f, -0.5f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f };
177+
178+
float v;
179+
int i;
180+
for ( i = 0; i < 10; i++ ) {
181+
v = stdlib_base_aversinf( x[ i ] );
182+
printf( "aversinf(%f) = %f\n", x[ i ], v );
183+
}
184+
}
185+
```
186+
187+
</section>
188+
189+
<!-- /.examples -->
190+
191+
</section>
192+
193+
<!-- /.c -->
194+
195+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
196+
197+
<section class="related">
198+
199+
</section>
200+
201+
<!-- /.related -->
202+
203+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
204+
205+
<section class="links">
206+
207+
[inverse-versed-sine]: https://en.wikipedia.org/wiki/Versine
208+
209+
<!-- <related-links> -->
210+
211+
<!-- </related-links> -->
212+
213+
</section>
214+
215+
<!-- /.links -->
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pkg = require( './../package.json' ).name;
27+
var aversinf = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var y;
35+
var i;
36+
37+
x = randu( 100, 0.0, 2.0 );
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
y = aversinf( x[ i % x.length ] );
42+
if ( isnanf( y ) ) {
43+
b.fail( 'should not return NaN' );
44+
}
45+
}
46+
b.toc();
47+
if ( isnanf( y ) ) {
48+
b.fail( 'should not return NaN' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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/array/uniform' );
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 aversinf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( aversinf 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+
x = randu( 100, 0.0, 2.0 );
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
y = aversinf( x[ i % x.length ] );
51+
if ( isnanf( y ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnanf( y ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});

0 commit comments

Comments
 (0)