Skip to content

Commit b2268e5

Browse files
authored
feat: add math/base/special/acoversinf
PR-URL: #2860 Ref: #649 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 3e80682 commit b2268e5

File tree

28 files changed

+1967
-0
lines changed

28 files changed

+1967
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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+
# Arccoversinef
22+
23+
> Compute the [inverse coversed sine][inverse-coversed-sine] of a single-precision floating-point number (in radians).
24+
25+
<section class="intro">
26+
27+
The [inverse coversed sine][inverse-coversed-sine] is defined as
28+
29+
<!-- <equation class="equation" label="eq:arccoversine" align="center" raw="\operatorname{acoversinf}(\theta) = \arcsin(1-\theta)" alt="Inverse coversed sine."> -->
30+
31+
```math
32+
\mathop{\mathrm{acoversinf}}(\theta) = \arcsin(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 acoversinf = require( '@stdlib/math/base/special/acoversinf' );
47+
```
48+
49+
#### acoversinf( x )
50+
51+
Computes the [inverse coversed sine][inverse-coversed-sine] of a single-precision floating-point number (in radians).
52+
53+
```javascript
54+
var v = acoversinf( 0.0 );
55+
// returns ~1.5708
56+
57+
v = acoversinf( 3.141592653589793 / 2.0 );
58+
// returns ~-0.6075
59+
60+
v = acoversinf( 3.141592653589793 / 6.0 );
61+
// returns ~0.4966
62+
```
63+
64+
If `x < 0`, `x > 2`, or `x` is `NaN`, the function returns `NaN`.
65+
66+
```javascript
67+
var v = acoversinf( -1.0 );
68+
// returns NaN
69+
70+
v = acoversinf( 3.14 );
71+
// returns NaN
72+
73+
v = acoversinf( 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 acoversinf = require( '@stdlib/math/base/special/acoversinf' );
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( acoversinf( 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/acoversinf.h"
127+
```
128+
129+
#### stdlib_base_acoversinf( x )
130+
131+
Computes the [inverse coversed sine][inverse-coversed-sine] of a single-precision floating-point number (in radians).
132+
133+
```c
134+
float out = stdlib_base_acoversinf( 3.141592653589793f / 2.0f );
135+
// returns ~-0.6075f
136+
```
137+
138+
The function accepts the following arguments:
139+
140+
- **x**: `[in] float` input value.
141+
142+
```c
143+
float stdlib_base_acoversinf( const float x );
144+
```
145+
146+
</section>
147+
148+
<!-- /.usage -->
149+
150+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
151+
152+
<section class="notes">
153+
154+
</section>
155+
156+
<!-- /.notes -->
157+
158+
<!-- C API usage examples. -->
159+
160+
<section class="examples">
161+
162+
### Examples
163+
164+
```c
165+
#include "stdlib/math/base/special/acoversinf.h"
166+
#include <stdio.h>
167+
168+
int main( void ) {
169+
const float x[] = { -5.0f, -3.89f, -2.78f, -1.67f, -0.56f, 0.56f, 1.67f, 2.78f, 3.89f, 5.0f };
170+
171+
float v;
172+
int i;
173+
for ( i = 0; i < 10; i++ ) {
174+
v = stdlib_base_acoversinf( x[ i ] );
175+
printf( "acoversinf(%f) = %f\n", x[ i ], v );
176+
}
177+
}
178+
```
179+
180+
</section>
181+
182+
<!-- /.examples -->
183+
184+
</section>
185+
186+
<!-- /.c -->
187+
188+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
189+
190+
<section class="related">
191+
192+
</section>
193+
194+
<!-- /.related -->
195+
196+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
197+
198+
<section class="links">
199+
200+
[inverse-coversed-sine]: https://en.wikipedia.org/wiki/Versine
201+
202+
<!-- <related-links> -->
203+
204+
<!-- </related-links> -->
205+
206+
</section>
207+
208+
<!-- /.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 acoversinf = 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 = acoversinf( 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 acoversinf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( acoversinf 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 = acoversinf( 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)