Skip to content

Commit b18921a

Browse files
aayush0325kgryte
andauthored
feat: add math/base/special/acosdf
PR-URL: #3015 Ref: #649 Co-authored-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]> Reviewed-by: Gunj Joshi <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 7ef9d58 commit b18921a

File tree

28 files changed

+1965
-0
lines changed

28 files changed

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

0 commit comments

Comments
 (0)