Skip to content

Commit ed81430

Browse files
hrshyaPlaneshifter
andauthored
feat: add math/base/special/acothf
PR-URL: #9803 Ref: #649 Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Harsh <149176984+hrshya@users.noreply.github.com>
1 parent 5852d17 commit ed81430

36 files changed

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

0 commit comments

Comments
 (0)