Skip to content

Commit 93b6176

Browse files
committed
feat: add math/base/special/sech
1 parent 41e8c89 commit 93b6176

File tree

30 files changed

+592
-570
lines changed

30 files changed

+592
-570
lines changed

lib/node_modules/@stdlib/math/base/special/sech/README.md

Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ limitations under the License.
1818
1919
-->
2020

21-
# Hyperbolic Secant
21+
# sech
2222

23-
> Evaluate the [hyperbolic secant][trigonometric-functions] of a number.
24-
25-
<section class="intro">
26-
27-
</section>
23+
> Compute the [hyperbolic cosecant][hyperbolic-functions] of a double-precision floating-point number.
2824
2925
<section class="usage">
3026

@@ -34,9 +30,9 @@ limitations under the License.
3430
var sech = require( '@stdlib/math/base/special/sech' );
3531
```
3632

37-
## csc( x )
33+
#### sech( x )
3834

39-
Evaluates the [hyperbolic secant][trigonometric-functions] of `x` (in radians).
35+
Computes the [hyperbolic cosecant][hyperbolic-functions] of a double-precision floating-point number.
4036

4137
```javascript
4238
var v = sech( 0.0 );
@@ -66,7 +62,7 @@ v = sech( NaN );
6662
var linspace = require( '@stdlib/array/base/linspace' );
6763
var sech = require( '@stdlib/math/base/special/sech' );
6864

69-
var x = linspace( -10, 10, 100 );
65+
var x = linspace( -5.0, 5.0, 100 );
7066

7167
var i;
7268
for ( i = 0; i < x.length; i++ ) {
@@ -78,30 +74,108 @@ for ( i = 0; i < x.length; i++ ) {
7874

7975
<!-- /.examples -->
8076

81-
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
82-
83-
<section class="related">
77+
<!-- C interface documentation. -->
8478

8579
* * *
8680

87-
## See Also
81+
<section class="c">
8882

89-
<span class="package-name">[`@stdlib/math/base/special/cosh`][@stdlib/math/base/special/cosh]</span><span class="delimiter">: </span><span class="description">evaluate the hyperbolic cosine of a number.</span>
83+
## C APIs
84+
85+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
86+
87+
<section class="intro">
9088

9189
</section>
9290

91+
<!-- /.intro -->
92+
93+
<!-- C usage documentation. -->
94+
95+
<section class="usage">
96+
97+
### Usage
98+
99+
```c
100+
#include "stdlib/math/base/special/sech.h"
101+
```
102+
103+
#### stdlib_base_sech( x )
104+
105+
Computes the [hyperbolic cosecant][hyperbolic-functions] of double-precision floating-point number.
106+
107+
```c
108+
double out = stdlib_base_sech( 2.0 );
109+
// returns ~0.2658
110+
111+
out = stdlib_base_sech( -2.0 );
112+
// returns ~0.2658
113+
```
114+
115+
The function accepts the following arguments:
116+
117+
- **x**: `[in] double` input value.
118+
119+
```c
120+
double stdlib_base_sech( const double x );
121+
```
122+
123+
</section>
124+
125+
<!-- /.usage -->
126+
127+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
128+
129+
<section class="notes">
130+
131+
</section>
132+
133+
<!-- /.notes -->
134+
135+
<!-- C API usage examples. -->
136+
137+
<section class="examples">
138+
139+
### Examples
140+
141+
```c
142+
#include "stdlib/math/base/special/sech.h"
143+
#include <stdio.h>
144+
145+
int main( void ) {
146+
const double x[] = { -4.0, -3.11, -2.22, -1.33, -0.44, 0.44, 1.33, 2.22, 3.11, 4.0 };
147+
148+
double v;
149+
int i;
150+
for ( i = 0; i < 10; i++ ) {
151+
v = stdlib_base_sech( x[ i ] );
152+
printf( "sech(%lf) = %lf\n", x[ i ], v );
153+
}
154+
}
155+
```
156+
157+
</section>
158+
159+
<!-- /.examples -->
160+
161+
</section>
162+
163+
<!-- /.c -->
164+
165+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
166+
167+
<section class="related">
168+
93169
<!-- /.related -->
94170

95171
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
96172

97173
<section class="links">
98174

99-
[trigonometric-functions]: https://en.wikipedia.org/wiki/Trigonometric_functions
175+
[hyperbolic-functions]: https://en.wikipedia.org/wiki/Hyperbolic_functions
100176

101177
<!-- <related-links> -->
102178

103-
[@stdlib/math/base/special/cosh]: https://github.com/stdlib-js/math/tree/main/base/special/cosh
104-
105179
<!-- </related-links> -->
106180

107181
</section>

lib/node_modules/@stdlib/math/base/special/sech/benchmark/benchmark.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var randu = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var cosh = require( '@stdlib/math/base/special/cosh' );
27-
var sech = require( './../lib' );
2826
var pkg = require( './../package.json' ).name;
27+
var sech = require( './../lib' );
2928

3029

3130
// MAIN //
@@ -35,33 +34,13 @@ bench( pkg, function benchmark( b ) {
3534
var y;
3635
var i;
3736

38-
b.tic();
39-
for ( i = 0; i < b.iterations; i++ ) {
40-
x = ( randu() * 20.0 ) - 10.0;
41-
y = sech(x);
42-
if ( isnan( y ) ) {
43-
b.fail( 'should not return NaN' );
44-
}
45-
}
46-
b.toc();
47-
if ( isnan( y ) ) {
48-
b.fail( 'should not return NaN' );
49-
}
50-
b.pass( 'benchmark finished' );
51-
b.end();
52-
});
53-
54-
bench(pkg + '::built-in', function benchmark( b ) {
55-
var x;
56-
var y;
57-
var i;
37+
x = randu( 100, -5.0, 5.0 );
5838

5939
b.tic();
6040
for ( i = 0; i < b.iterations; i++ ) {
61-
x = ( randu() * 20.0 ) - 10.0;
62-
y = 1.0 / cosh( x );
41+
y = sech( x[ i % x.length ] );
6342
if ( isnan( y ) ) {
64-
b.fail('should not return NaN');
43+
b.fail( 'should not return NaN' );
6544
}
6645
}
6746
b.toc();

lib/node_modules/@stdlib/math/base/special/sech/benchmark/benchmark.native.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,34 @@
2020

2121
// MODULES //
2222

23+
var resolve = require( 'path' ).resolve;
2324
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
25+
var randu = require( '@stdlib/random/array/uniform' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
2628
var pkg = require( './../package.json' ).name;
2729

2830

2931
// VARIABLES //
3032

31-
var sech = require( './../lib/native.js' );
33+
var sech = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3234
var opts = {
33-
'skip': (sech instanceof Error)
35+
'skip': ( sech instanceof Error )
3436
};
3537

3638

3739
// MAIN //
3840

39-
bench( pkg + '::native', opts, function benchmark( b ) {
41+
bench( pkg+'::native', opts, function benchmark( b ) {
4042
var x;
4143
var y;
4244
var i;
4345

46+
x = randu( 100, -5.0, 5.0 );
47+
4448
b.tic();
4549
for ( i = 0; i < b.iterations; i++ ) {
46-
x = ( randu() * 10.0 ) - 5.0;
47-
y = sech(x);
50+
y = sech( x[ i % x.length ] );
4851
if ( isnan( y ) ) {
4952
b.fail( 'should not return NaN' );
5053
}

lib/node_modules/@stdlib/math/base/special/sech/benchmark/c/Makefile

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)