Skip to content

Commit ecf1c08

Browse files
feat: add math/base/special/cscdf
PR-URL: #7868 Ref: #649 Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]> Signed-off-by: Karan Anand <[email protected]>
1 parent 7748b7c commit ecf1c08

File tree

28 files changed

+1961
-0
lines changed

28 files changed

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