Skip to content

Commit d18f275

Browse files
feat: add math/base/special/fast/acoshf
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 4304bee commit d18f275

File tree

30 files changed

+2035
-0
lines changed

30 files changed

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

0 commit comments

Comments
 (0)