Skip to content

Commit bb6ac7e

Browse files
the-r3aper7stdlib-botPlaneshifter
authored
feat: add math/base/special/cscd
PR-URL: #1786 Closes: #39 --------- Signed-off-by: Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 665c735 commit bb6ac7e

File tree

14 files changed

+667
-0
lines changed

14 files changed

+667
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
# cscd
22+
23+
> Compute the [cosecant][cosecant] of a degree.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var cscd = require( '@stdlib/math/base/special/cscd' );
31+
```
32+
33+
#### cscd( x )
34+
35+
Computes the [cosecant][cosecant] of `x` (in degrees).
36+
37+
```javascript
38+
var v = cscd( 30 );
39+
// returns ~2.0
40+
41+
v = cscd( 45 );
42+
// returns ~1.41
43+
44+
v = cscd( 60 );
45+
// returns ~1.15
46+
47+
v = cscd( 90 );
48+
// returns 1.0
49+
50+
v = cscd( 0 );
51+
// returns Infinity
52+
53+
v = cscd( 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 linspace = require( '@stdlib/array/base/linspace' );
69+
var cscd = require( '@stdlib/math/base/special/cscd' );
70+
71+
var x = linspace( 1.1, 5.1, 100 );
72+
73+
var i;
74+
for ( i = 0; i < x.length; i++ ) {
75+
console.log( cscd( x[ i ] ) );
76+
}
77+
```
78+
79+
</section>
80+
81+
<!-- /.examples -->
82+
83+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
84+
85+
<section class="related">
86+
87+
</section>
88+
89+
<!-- /.related -->
90+
91+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
92+
93+
<section class="links">
94+
95+
[cosecant]: https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
96+
97+
<!-- <related-links> -->
98+
99+
<!-- </related-links> -->
100+
101+
</section>
102+
103+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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/base/randu' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pkg = require( './../package.json' ).name;
27+
var cscd = 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()*2.0 ) + 1.0;
40+
y = cscd( x );
41+
if ( isnan( y ) ) {
42+
b.fail( 'should not return NaN' );
43+
}
44+
}
45+
b.toc();
46+
if ( isnan( 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,28 @@
1+
2+
{{alias}}( x )
3+
Computes the cosecant of a degree.
4+
5+
Parameters
6+
----------
7+
x: number
8+
Input value (in degrees).
9+
10+
Returns
11+
-------
12+
y: number
13+
Cosecant.
14+
15+
Examples
16+
--------
17+
> var y = {{alias}}( 1.0 )
18+
~57.30
19+
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}} )
20+
~18.25
21+
> y = {{alias}}( -{{alias:@stdlib/constants/float64/pi}} )
22+
~-18.25
23+
> y = {{alias}}( NaN )
24+
NaN
25+
26+
See Also
27+
--------
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Computes the cosecant of a degree.
23+
*
24+
* @param x - input value (in degrees)
25+
* @returns cosecant
26+
*
27+
* @example
28+
* var v = cscd( 30 );
29+
* // returns ~2.0
30+
*
31+
* @example
32+
* var v = cscd( 45 );
33+
* // returns ~1.41
34+
*
35+
* @example
36+
* var v = cscd( 60 );
37+
* // returns ~1.15
38+
*
39+
* @example
40+
* var v = cscd( 90 );
41+
* // returns 1.0
42+
*
43+
* @example
44+
* var v = cscd( 0 );
45+
* // returns Infinity
46+
*
47+
* @example
48+
* var v = cscd( NaN );
49+
* // returns NaN
50+
*/
51+
declare function cscd( x: number ): number;
52+
53+
54+
// EXPORTS //
55+
56+
export = cscd;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
import cscd = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
cscd( 8 ); // $ExpectType number
27+
}
28+
29+
// The compiler throws an error if the function is provided a value other than a number...
30+
{
31+
cscd( true ); // $ExpectError
32+
cscd( false ); // $ExpectError
33+
cscd( null ); // $ExpectError
34+
cscd( undefined ); // $ExpectError
35+
cscd( '5' ); // $ExpectError
36+
cscd( [] ); // $ExpectError
37+
cscd( {} ); // $ExpectError
38+
cscd( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided insufficient arguments...
42+
{
43+
cscd(); // $ExpectError
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
var linspace = require( '@stdlib/array/base/linspace' );
22+
var cscd = require( './../lib' );
23+
24+
var x = linspace( 1.1, 5.1, 100 );
25+
26+
var i;
27+
for ( i = 0; i < x.length; i++ ) {
28+
console.log( 'cscd(%d) = %d', x[ i ], cscd( x[ i ] ) );
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
/**
22+
* Compute the cosecant of a degree.
23+
*
24+
* @module @stdlib/math/base/special/cscd
25+
*
26+
* @example
27+
* var cscd = require( '@stdlib/math/base/special/cscd' );
28+
*
29+
* var v = cscd( 30 );
30+
* // returns ~2.0
31+
*
32+
* var v = cscd( 45 );
33+
* // returns ~1.41
34+
*
35+
* var v = cscd( 60 );
36+
* // returns ~1.15
37+
*
38+
* var v = cscd( 90 );
39+
* // returns 1.0
40+
*
41+
* var v = cscd( 0 );
42+
* // returns Infinity
43+
*
44+
* var v = cscd( NaN );
45+
* // returns NaN
46+
*/
47+
48+
// MODULES //
49+
50+
var main = require( './main.js' );
51+
52+
53+
// EXPORTS //
54+
55+
module.exports = main;

0 commit comments

Comments
 (0)