Skip to content

Commit fc38ed8

Browse files
feat: add math/base/special/ahavercosf
PR-URL: #3072 Closes: #649 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]> Signed-off-by: Philipp Burckhardt <[email protected]>
1 parent e093a4d commit fc38ed8

31 files changed

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