Skip to content

Commit f01384c

Browse files
feat: add math/base/special/acosd
PR-URL: #1782 Closes: #36 --------- Signed-off-by: Sai Srikar Dumpeti <[email protected]> Signed-off-by: Philipp Burckhardt <[email protected]> Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 8282820 commit f01384c

File tree

14 files changed

+684
-0
lines changed

14 files changed

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

0 commit comments

Comments
 (0)