Skip to content

Commit 641fb85

Browse files
committed
feat: add math/base/special/versinf
--- 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 3981497 commit 641fb85

34 files changed

+358
-405
lines changed

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

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2018 The Stdlib Authors.
5+
Copyright (c) 2025 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# Versine
2222

23-
> Compute the [versed sine][versed-sine].
23+
> Compute the [versed sine][versed-sine] of a single-precision floating-point number (in radians).
2424
2525
<section class="intro">
2626

@@ -32,11 +32,6 @@ The [versed sine][versed-sine] is defined as
3232
\mathop{\mathrm{versin}}(\theta) = 1 - \cos \theta
3333
```
3434

35-
<!-- <div class="equation" align="center" data-raw-text="\operatorname{versin}(\theta) = 1 - \cos \theta" data-equation="eq:versine">
36-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/versin/docs/img/equation_versine.svg" alt="Versed sine.">
37-
<br>
38-
</div> -->
39-
4035
<!-- </equation> -->
4136

4237
</section>
@@ -48,21 +43,21 @@ The [versed sine][versed-sine] is defined as
4843
## Usage
4944

5045
```javascript
51-
var versin = require( '@stdlib/math/base/special/versin' );
46+
var versinf = require( '@stdlib/math/base/special/versinf' );
5247
```
5348

54-
#### versin( x )
49+
#### versinf( x )
5550

56-
Computes the [versed sine][versed-sine] of a `number` (in radians).
51+
Computes the [versed sine][versed-sine] of a single-precision floating-point number (in radians).
5752

5853
```javascript
59-
var v = versin( 0.0 );
54+
var v = versinf( 0.0 );
6055
// returns 0.0
6156

62-
v = versin( 3.141592653589793/2.0 );
57+
v = versinf( 3.141592653589793/2.0 );
6358
// returns ~1.0
6459

65-
v = versin( -3.141592653589793/6.0 );
60+
v = versinf( -3.141592653589793/6.0 );
6661
// returns ~0.13397
6762
```
6863

@@ -79,15 +74,15 @@ v = versin( -3.141592653589793/6.0 );
7974
```javascript
8075
var uniform = require( '@stdlib/random/array/uniform' );
8176
var logEachMap = require( '@stdlib/console/log-each-map' );
82-
var TWO_PI = require( '@stdlib/constants/float64/two-pi' );
83-
var versin = require( '@stdlib/math/base/special/versin' );
77+
var TWO_PI = require( '@stdlib/constants/float32/two-pi' );
78+
var versinf = require( '@stdlib/math/base/special/versinf' );
8479

8580
var opts = {
86-
'dtype': 'float64'
81+
'dtype': 'float32'
8782
};
8883
var x = uniform( 100, 0.0, TWO_PI, opts );
8984

90-
logEachMap( 'versin(%0.4f) = %0.4f', x, versin );
85+
logEachMap( 'versinf(%0.4f) = %0.4f', x, versinf );
9186
```
9287

9388
</section>
@@ -117,27 +112,27 @@ logEachMap( 'versin(%0.4f) = %0.4f', x, versin );
117112
### Usage
118113

119114
```c
120-
#include "stdlib/math/base/special/versin.h"
115+
#include "stdlib/math/base/special/versinf.h"
121116
```
122117

123-
#### stdlib_base_versin( x )
118+
#### stdlib_base_versinf( x )
124119

125-
Computes the [versed sine][versed-sine] of a `number` (in radians).
120+
Computes the [versed sine][versed-sine] of a single-precision floating-point number (in radians).
126121

127122
```c
128-
double out = stdlib_base_versin( 0.0 );
129-
// returns 0.0
123+
float out = stdlib_base_versinf( 0.0f );
124+
// returns 0.0f
130125

131-
out = stdlib_base_versin( 3.141592653589793 / 2.0 );
132-
// returns ~1.0
126+
out = stdlib_base_versinf( 3.141592653589793f / 2.0f );
127+
// returns ~1.0f
133128
```
134129

135130
The function accepts the following arguments:
136131

137-
- **x**: `[in] double` input value.
132+
- **x**: `[in] float` input value.
138133

139134
```c
140-
double stdlib_base_versin( const double x );
135+
float stdlib_base_versinf( const float x );
141136
```
142137
143138
</section>
@@ -159,17 +154,17 @@ double stdlib_base_versin( const double x );
159154
### Examples
160155
161156
```c
162-
#include "stdlib/math/base/special/versin.h"
157+
#include "stdlib/math/base/special/versinf.h"
163158
#include <stdio.h>
164159
165160
int main( void ) {
166-
const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 };
161+
const float x[] = { 0.0f, 0.523f, 0.785f, 1.047f, 3.14f };
167162
168-
double y;
163+
float y;
169164
int i;
170165
for ( i = 0; i < 5; i++ ) {
171-
y = stdlib_base_versin( x[ i ] );
172-
printf( "versin(%lf) = %lf\n", x[ i ], y );
166+
y = stdlib_base_versinf( x[ i ] );
167+
printf( "versinf(%f) = %f\n", x[ i ], y );
173168
}
174169
}
175170
```
@@ -186,14 +181,6 @@ int main( void ) {
186181

187182
<section class="related">
188183

189-
* * *
190-
191-
## See Also
192-
193-
- <span class="package-name">[`@stdlib/math/base/special/cos`][@stdlib/math/base/special/cos]</span><span class="delimiter">: </span><span class="description">compute the cosine of a number.</span>
194-
- <span class="package-name">[`@stdlib/math/base/special/sin`][@stdlib/math/base/special/sin]</span><span class="delimiter">: </span><span class="description">compute the sine of a number.</span>
195-
- <span class="package-name">[`@stdlib/math/base/special/vercos`][@stdlib/math/base/special/vercos]</span><span class="delimiter">: </span><span class="description">compute the versed cosine.</span>
196-
197184
</section>
198185

199186
<!-- /.related -->
@@ -206,12 +193,6 @@ int main( void ) {
206193

207194
<!-- <related-links> -->
208195

209-
[@stdlib/math/base/special/cos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cos
210-
211-
[@stdlib/math/base/special/sin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sin
212-
213-
[@stdlib/math/base/special/vercos]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/vercos
214-
215196
<!-- </related-links> -->
216197

217198
</section>

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var uniform = require( '@stdlib/random/array/uniform' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
27-
var versin = require( './../lib' );
27+
var versinf = require( './../lib' );
2828

2929

3030
// MAIN //
@@ -34,17 +34,19 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37-
x = uniform( 100, -10.0, 10.0 );
37+
x = uniform( 100, -10.0, 10.0, {
38+
'dtype': 'float32'
39+
});
3840

3941
b.tic();
4042
for ( i = 0; i < b.iterations; i++ ) {
41-
y = versin( x[ i % x.length ] );
42-
if ( isnan( y ) ) {
43+
y = versinf( x[ i%x.length ] );
44+
if ( isnanf( y ) ) {
4345
b.fail( 'should not return NaN' );
4446
}
4547
}
4648
b.toc();
47-
if ( isnan( y ) ) {
49+
if ( isnanf( y ) ) {
4850
b.fail( 'should not return NaN' );
4951
}
5052
b.pass( 'benchmark finished' );

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -23,16 +23,16 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var uniform = require( '@stdlib/random/array/uniform' );
26-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
2929

3030

3131
// VARIABLES //
3232

33-
var versin = tryRequire( resolve( __dirname, './../lib/native.js' ) );
33+
var versinf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3434
var opts = {
35-
'skip': ( versin instanceof Error )
35+
'skip': ( versinf instanceof Error )
3636
};
3737

3838

@@ -43,17 +43,19 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = uniform( 100, -10.0, 10.0 );
46+
x = uniform( 100, -10.0, 10.0, {
47+
'dtype': 'float32'
48+
});
4749

4850
b.tic();
4951
for ( i = 0; i < b.iterations; i++ ) {
50-
y = versin( x[ i % x.length ] );
51-
if ( isnan( y ) ) {
52+
y = versinf( x[ i%x.length ] );
53+
if ( isnanf( y ) ) {
5254
b.fail( 'should not return NaN' );
5355
}
5456
}
5557
b.toc();
56-
if ( isnan( y ) ) {
58+
if ( isnanf( y ) ) {
5759
b.fail( 'should not return NaN' );
5860
}
5961
b.pass( 'benchmark finished' );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2018 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/math/base/special/versinf/benchmark/c/benchmark.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
#include <time.h>
2323
#include <sys/time.h>
2424

25-
#define NAME "versin"
25+
#define NAME "versinf"
2626
#define ITERATIONS 1000000
2727
#define REPEATS 3
2828

@@ -74,13 +74,15 @@ static double tic( void ) {
7474
}
7575

7676
/**
77-
* Generates a random number on the interval [0,1).
77+
* Generates a random number on the interval [min,max).
7878
*
79-
* @return random number
79+
* @param min minimum value (inclusive)
80+
* @param max maximum value (exclusive)
81+
* @return random number
8082
*/
81-
static double rand_double( void ) {
82-
int r = rand();
83-
return (double)r / ( (double)RAND_MAX + 1.0 );
83+
static float random_uniform( const float min, const float max ) {
84+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
85+
return min + ( v*(max-min) );
8486
}
8587

8688
/**
@@ -89,19 +91,19 @@ static double rand_double( void ) {
8991
* @return elapsed time in seconds
9092
*/
9193
static double benchmark( void ) {
92-
double x[ 100 ];
94+
float x[ 100 ];
9395
double elapsed;
94-
double y;
9596
double t;
97+
float y;
9698
int i;
9799

98100
for ( i = 0; i < 100; i++ ) {
99-
x[ i ] = ( 20.0*rand_double() ) - 10.0;
101+
x[ i ] = random_uniform( -10.0f, 10.0f );
100102
}
101103

102104
t = tic();
103105
for ( i = 0; i < ITERATIONS; i++ ) {
104-
y = 1.0 - cos( x[ i%100 ] );
106+
y = 1.0f - cosf( x[ i%100 ] );
105107
if ( y != y ) {
106108
printf( "should not return NaN\n" );
107109
break;

lib/node_modules/@stdlib/math/base/special/versinf/benchmark/c/native/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)