Skip to content

Commit 0160d55

Browse files
feat: add math/base/special/covercosf
PR-URL: #7303 Ref: #649 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent d2c372a commit 0160d55

34 files changed

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

0 commit comments

Comments
 (0)