Skip to content

Commit 01cbab9

Browse files
gunjjoshikgryte
andauthored
feat: add math/base/special/acotf
PR-URL: #2117 Closes: #2113 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Pranav Goswami <goswami.4@iitj.ac.in> Signed-off-by: GUNJ JOSHI <gunjjoshi8372@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent 1e4b912 commit 01cbab9

34 files changed

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

0 commit comments

Comments
 (0)