Skip to content

Commit 9958b9b

Browse files
committed
feat: add C implementation for @stdlib/math/base/special/asechf
1 parent e924862 commit 9958b9b

File tree

22 files changed

+1630
-0
lines changed

22 files changed

+1630
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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+
# asechf
22+
23+
> Compute the [hyperbolic arcsecant][hyperbolic-arcsecant] of a single-precision floating-point number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var asechf = require( '@stdlib/math/base/special/asechf' );
31+
```
32+
33+
#### asechf( x )
34+
35+
Computes the [hyperbolic arcsecant][hyperbolic-arcsecant] of a single-precision floating-point number.
36+
37+
```javascript
38+
var v = asechf( 1.0 );
39+
// returns 0.0
40+
41+
v = asechf( 0.5 );
42+
// returns ~1.317
43+
44+
v = asechf( 0.0 );
45+
// returns Infinity
46+
```
47+
48+
The domain of `x` is restricted to the interval `[0, 1]`. For `x` outside of this interval, the function returns `NaN`.
49+
50+
```javascript
51+
var v = asechf( -1.0 );
52+
// returns NaN
53+
54+
v = asechf( 2.0 );
55+
// returns NaN
56+
```
57+
58+
</section>
59+
60+
<!-- /.usage -->
61+
62+
<section class="examples">
63+
64+
## Examples
65+
66+
<!-- eslint no-undef: "error" -->
67+
68+
```javascript
69+
var uniform = require( '@stdlib/random/array/uniform' );
70+
var logEachMap = require( '@stdlib/console/log-each-map' );
71+
var asechf = require( '@stdlib/math/base/special/asechf' );
72+
73+
var x = uniform( 100, 0.1, 1.0, {
74+
'dtype': 'float32'
75+
});
76+
77+
logEachMap( 'asechf(%0.4f) = %0.4f', x, asechf );
78+
```
79+
80+
</section>
81+
82+
<!-- /.examples -->
83+
84+
<!-- C interface documentation. -->
85+
86+
* * *
87+
88+
<section class="c">
89+
90+
## C APIs
91+
92+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
93+
94+
<section class="intro">
95+
96+
</section>
97+
98+
<!-- /.intro -->
99+
100+
<!-- C usage documentation. -->
101+
102+
<section class="usage">
103+
104+
### Usage
105+
106+
```c
107+
#include "stdlib/math/base/special/asechf.h"
108+
```
109+
110+
#### stdlib_base_asechf( x )
111+
112+
Computes the [hyperbolic arcsecant][hyperbolic-arcsecant] of a single-precision floating-point number.
113+
114+
```c
115+
float out = stdlib_base_asechf( 0.5f );
116+
// returns ~1.317f
117+
```
118+
119+
The function accepts the following arguments:
120+
121+
- **x**: `[in] float` input value.
122+
123+
```c
124+
float stdlib_base_asechf( const float x );
125+
```
126+
127+
</section>
128+
129+
<!-- /.usage -->
130+
131+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="notes">
134+
135+
</section>
136+
137+
<!-- /.notes -->
138+
139+
<!-- C API usage examples. -->
140+
141+
<section class="examples">
142+
143+
### Examples
144+
145+
```c
146+
#include "stdlib/math/base/special/asechf.h"
147+
#include <stdio.h>
148+
149+
int main( void ) {
150+
const float x[] = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f };
151+
152+
float v;
153+
int i;
154+
for ( i = 0; i < 10; i++ ) {
155+
v = stdlib_base_asechf( x[ i ] );
156+
printf( "asechf(%f) = %f\n", x[ i ], v );
157+
}
158+
}
159+
```
160+
161+
</section>
162+
163+
<!-- /.examples -->
164+
165+
</section>
166+
167+
<!-- /.c -->
168+
169+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
170+
171+
<section class="related">
172+
173+
* * *
174+
175+
## See Also
176+
177+
- <span class="package-name">[`@stdlib/math/base/special/asech`][@stdlib/math/base/special/asech]</span><span class="delimiter">: </span><span class="description">compute the hyperbolic arcsecant of a number.</span>
178+
- <span class="package-name">[`@stdlib/math/base/special/asecf`][@stdlib/math/base/special/asecf]</span><span class="delimiter">: </span><span class="description">compute the inverse (arc) secant of a single-precision floating-point number.</span>
179+
- <span class="package-name">[`@stdlib/math/base/special/acosh`][@stdlib/math/base/special/acosh]</span><span class="delimiter">: </span><span class="description">compute the hyperbolic arccosine of a double-precision floating-point number.</span>
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+
[hyperbolic-arcsecant]: https://en.wikipedia.org/wiki/Inverse_hyperbolic_functions
190+
191+
<!-- <related-links> -->
192+
193+
[@stdlib/math/base/special/asech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/asech
194+
195+
[@stdlib/math/base/special/asecf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/asecf
196+
197+
[@stdlib/math/base/special/acosh]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/acosh
198+
199+
<!-- </related-links> -->
200+
201+
</section>
202+
203+
<!-- /.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) 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 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 asechf = 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();
40+
y = asechf( 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) 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 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 asechf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( asechf 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();
49+
y = asechf( 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)