Skip to content

Commit 5b72836

Browse files
feat: add math/base/special/asecd
PR-URL: #1788 Closes: #41 --------- Signed-off-by: Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 229be91 commit 5b72836

File tree

14 files changed

+695
-0
lines changed

14 files changed

+695
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
# asecd
22+
23+
> Compute the [arcsecant][arcsecant] (in degrees) of a double-precision floating-point number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var asecd = require( '@stdlib/math/base/special/asecd' );
31+
```
32+
33+
#### asecd( x )
34+
35+
Computes the [arcsecant][arcsecant] (in degrees) of a double-precision floating-point number.
36+
37+
```javascript
38+
var sqrt = require( '@stdlib/math/base/special/sqrt' );
39+
var v = asecd( 1 );
40+
// returns 0.0
41+
42+
v = asecd( 2 * sqrt( 3 ) / 3 );
43+
// returns ~30.0
44+
45+
v = asecd( sqrt( 2 ) );
46+
// returns ~45.0
47+
48+
v = asecd( 2 );
49+
// returns ~60.0
50+
51+
v = asecd( Infinity );
52+
// returns 90.0
53+
54+
v = asecd( NaN );
55+
// returns NaN
56+
```
57+
58+
</section>
59+
60+
<!-- /.usage -->
61+
62+
<section class="examples">
63+
64+
## Examples
65+
66+
<!-- eslint no-undef: "error" -->
67+
68+
```javascript
69+
var linspace = require( '@stdlib/array/base/linspace' );
70+
var asecd = require( '@stdlib/math/base/special/asecd' );
71+
72+
var x = linspace( -1.0, 1.0, 100 );
73+
74+
var i;
75+
for ( i = 0; i < x.length; i++ ) {
76+
console.log( asecd( x[ i ] ) );
77+
}
78+
```
79+
80+
</section>
81+
82+
<!-- /.examples -->
83+
84+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
85+
86+
<section class="related">
87+
88+
</section>
89+
90+
<!-- /.related -->
91+
92+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
93+
94+
<section class="links">
95+
96+
[arcsecant]: https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
97+
98+
<!-- <related-links> -->
99+
100+
<!-- </related-links> -->
101+
102+
</section>
103+
104+
<!-- /.links -->
Lines changed: 51 additions & 0 deletions
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 asecd = 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 = asecd( 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+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( x )
3+
Computes the arcsecant (in degrees) of a double-precision floating-point
4+
number.
5+
6+
If `x` does not satisy `x >= 1` or `x <= -1`, the function returns NaN.
7+
8+
Parameters
9+
----------
10+
x: number
11+
Input value.
12+
13+
Returns
14+
-------
15+
y: number
16+
Arcsecant (in degrees).
17+
18+
Examples
19+
--------
20+
> var y = {{alias}}( 0.0 )
21+
NaN
22+
> y = {{alias}}( 2 )
23+
~60.0
24+
> y = {{alias}}( NaN )
25+
NaN
26+
27+
See Also
28+
--------
29+
Lines changed: 56 additions & 0 deletions
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 arcsecant (in degrees) of a double-precision floating-point number.
23+
*
24+
* @param x - input value
25+
* @returns arcsecant (in degrees)
26+
*
27+
* @example
28+
* var v = asecd( 1 );
29+
* // returns 0.0
30+
*
31+
* @example
32+
* var v = asecd( 2 * Math.sqrt( 3 ) / 3 );
33+
* // returns ~30.0
34+
*
35+
* @example
36+
* var v = asecd( Math.sqrt( 2 ) );
37+
* // returns ~45.0
38+
*
39+
* @example
40+
* var v = asecd( 2 );
41+
* // returns ~60.0
42+
*
43+
* @example
44+
* var v = asecd( Infinity );
45+
* // returns 90.0
46+
*
47+
* @example
48+
* var v = asecd( NaN );
49+
* // returns NaN
50+
*/
51+
declare function asecd( x: number ): number;
52+
53+
54+
// EXPORTS //
55+
56+
export = asecd;
Lines changed: 44 additions & 0 deletions
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 asecd = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
asecd( 1.2 ); // $ExpectType number
27+
}
28+
29+
// The compiler throws an error if the function is provided a value other than a number...
30+
{
31+
asecd( true ); // $ExpectError
32+
asecd( false ); // $ExpectError
33+
asecd( null ); // $ExpectError
34+
asecd( undefined ); // $ExpectError
35+
asecd( '5' ); // $ExpectError
36+
asecd( [] ); // $ExpectError
37+
asecd( {} ); // $ExpectError
38+
asecd( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided insufficient arguments...
42+
{
43+
asecd(); // $ExpectError
44+
}
Lines changed: 29 additions & 0 deletions
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 asecd = require( './../lib' );
23+
24+
var x = linspace( -10.0, 10.0, 100 );
25+
26+
var i;
27+
for ( i = 0; i < x.length; i++ ) {
28+
console.log( 'asecd(%d) = %d', x[ i ], asecd( x[ i ] ) );
29+
}
Lines changed: 55 additions & 0 deletions
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 arcsecant (in degrees) of a double-precision floating-point number.
23+
*
24+
* @module @stdlib/math/base/special/asecd
25+
*
26+
* @example
27+
* var asecd = require( '@stdlib/math/base/special/asecd' );
28+
*
29+
* var v = asecd( 1 );
30+
* // returns 0.0
31+
*
32+
* v = asecd( 2 * Math.sqrt( 3 ) / 3 );
33+
* // returns ~30.0
34+
*
35+
* v = asecd( Math.sqrt( 2 ) );
36+
* // returns ~45.0
37+
*
38+
* v = asecd( 2 );
39+
* // returns ~60.0
40+
*
41+
* v = asecd( Infinity );
42+
* // returns 90.0
43+
*
44+
* v = asecd( 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)