Skip to content

Commit a36eaf0

Browse files
committed
refactor: apply suggestions from PR review
--- 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: na - task: lint_license_headers status: passed ---
1 parent aef955f commit a36eaf0

File tree

18 files changed

+120
-116
lines changed

18 files changed

+120
-116
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# wrapf
2222

23-
> Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
23+
> Wrap a single-precision floating-point value to the half-open interval `[min,max)`.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -42,7 +42,7 @@ var wrapf = require( '@stdlib/math/base/special/wrapf' );
4242

4343
#### wrapf( v, min, max )
4444

45-
Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
45+
Wraps a single-precision floating-point value to the half-open interval `[min,max)`.
4646

4747
```javascript
4848
var v = wrapf( 3.14, 0.0, 5.0 );
@@ -106,20 +106,18 @@ var v = wrapf( 3.14, 3.0, 3.0 );
106106
<!-- eslint no-undef: "error" -->
107107

108108
```javascript
109-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
109+
var uniform = require( '@stdlib/random/array/uniform' );
110+
var logEachMap = require( '@stdlib/console/log-each-map' );
110111
var wrapf = require( '@stdlib/math/base/special/wrapf' );
111112

112-
var min;
113-
var max;
114-
var v;
115-
var i;
113+
var opts = {
114+
'dtype': 'float32'
115+
};
116+
var min = uniform( 100, 0.0, 10.0, opts );
117+
var max = uniform( 100, 5.0, 15.0, opts );
118+
var v = uniform( 100, -20.0, 20.0, opts );
116119

117-
for ( i = 0; i < 100; i++ ) {
118-
min = discreteUniform( 0.0, 10.0 );
119-
max = discreteUniform( 5.0, 15.0 );
120-
v = discreteUniform( -20.0, 20.0 );
121-
console.log( 'wrapf(%d,%d,%d) => %d', v, min, max, wrapf( v, min, max ) );
122-
}
120+
logEachMap( 'wrapf(%0.4f,%0.4f,%0.4f) => %0.4f', v, min, max, wrapf );
123121
```
124122

125123
</section>
@@ -154,14 +152,14 @@ for ( i = 0; i < 100; i++ ) {
154152

155153
#### stdlib_base_wrapf( v, min, max )
156154

157-
Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
155+
Wrap a single-precision floating-point value to the half-open interval `[min,max)`.
158156

159157
```c
160-
float v = stdlib_base_wrapf( 3.14, 0.0, 5.0 );
161-
// returns ~3.14
158+
float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f );
159+
// returns ~3.14f
162160

163-
v = stdlib_base_wrapf( -3.14, 0.0, 5.0 );
164-
// returns ~1.86
161+
v = stdlib_base_wrapf( -3.14f, 0.0f, 5.0f );
162+
// returns ~1.86f
165163
```
166164

167165
The function accepts the following arguments:

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/array/uniform' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var wrapf = require( './../lib' );
@@ -34,7 +34,9 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37-
x = randu( 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++ ) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/array/uniform' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -43,7 +43,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46-
x = randu( 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++ ) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static float rand_float( void ) {
8989
* @param v value to wrap
9090
* @param min minimum value
9191
* @param max maximum value
92-
* @return wrapped value
92+
* @return wrapped value
9393
*/
9494
float wrapf( float v, float min, float max ) {
9595
float delta;
@@ -99,9 +99,9 @@ float wrapf( float v, float min, float max ) {
9999
// Perform range reduction...
100100
delta = max - min;
101101
if ( v < min ) {
102-
v += delta * ( truncf( ( min - v ) / delta ) + 1.0 );
102+
v += delta * ( truncf( (min-v)/delta ) + 1.0f );
103103
}
104-
return min + fmodf( ( v - min ), delta );
104+
return min + fmodf( (v-min), delta );
105105
}
106106

107107
/**
@@ -111,18 +111,18 @@ float wrapf( float v, float min, float max ) {
111111
*/
112112
static double benchmark( void ) {
113113
double elapsed;
114-
double t;
115114
float x[ 100 ];
115+
double t;
116116
float y;
117117
int i;
118118

119119
for ( i = 0; i < 100; i++ ) {
120-
x[ i ] = ( 20.0f * rand_float() ) - 10.0f;
120+
x[ i ] = ( 20.0f*rand_float() ) - 10.0f;
121121
}
122122

123123
t = tic();
124124
for ( i = 0; i < ITERATIONS; i++ ) {
125-
y = wrapf( x[ i%100 ], -5.0, 5.0 );
125+
y = wrapf( x[ i%100 ], -5.0f, 5.0f );
126126
if ( y != y ) {
127127
printf( "should not return NaN\n" );
128128
break;

lib/node_modules/@stdlib/math/base/special/wrapf/benchmark/c/native/benchmark.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,18 @@ static float rand_float( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double t;
9594
float x[ 100 ];
95+
double t;
9696
float y;
9797
int i;
9898

9999
for ( i = 0; i < 100; i++ ) {
100-
x[ i ] = ( 20.0f * rand_float() ) - 10.0f;
100+
x[ i ] = ( 20.0f*rand_float() ) - 10.0f;
101101
}
102102

103103
t = tic();
104104
for ( i = 0; i < ITERATIONS; i++ ) {
105-
y = stdlib_base_wrapf( x[ i%100 ], -5.0, 5.0 );
105+
y = stdlib_base_wrapf( x[ i%100 ], -5.0f, 5.0f );
106106
if ( y != y ) {
107107
printf( "should not return NaN\n" );
108108
break;

lib/node_modules/@stdlib/math/base/special/wrapf/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{{alias}}( v, min, max )
3-
Wraps a value on the half-open interval `[min,max)` for single-precision
4-
floating-point numbers.
3+
Wraps a single-precision floating-point value to the half-open interval
4+
`[min,max)`.
55

66
The function does not distinguish between positive and negative zero. Where
77
appropriate, the function returns positive zero.

lib/node_modules/@stdlib/math/base/special/wrapf/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TypeScript Version: 4.1
2020

2121
/**
22-
* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
22+
* Wraps a single-precision floating-point value to the half-open interval `[min,max)`.
2323
*
2424
* @param v - input value
2525
* @param min - minimum value

lib/node_modules/@stdlib/math/base/special/wrapf/examples/c/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ int main( void ) {
2828
int i;
2929
for ( i = 0; i < 5; i++ ) {
3030
out = stdlib_base_wrapf( v[i], min[i], max[i] );
31-
printf( "wrap(%f,%f,%f) => %f\n", v[i], min[i], max[i], out );
31+
printf( "wrapf(%f,%f,%f) => %f\n", v[i], min[i], max[i], out );
3232
}
3333
}

lib/node_modules/@stdlib/math/base/special/wrapf/examples/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818

1919
'use strict';
2020

21-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var logEachMap = require( '@stdlib/console/log-each-map' );
2223
var wrapf = require( './../lib' );
2324

24-
var min;
25-
var max;
26-
var v;
27-
var i;
25+
var opts = {
26+
'dtype': 'float32'
27+
};
28+
var min = uniform( 100, 0.0, 10.0, opts );
29+
var max = uniform( 100, 5.0, 15.0, opts );
30+
var v = uniform( 100, -20.0, 20.0, opts );
2831

29-
for ( i = 0; i < 100; i++ ) {
30-
min = discreteUniform( 0.0, 10.0 );
31-
max = discreteUniform( 5.0, 15.0 );
32-
v = discreteUniform( -20.0, 20.0 );
33-
console.log( 'wrapf(%d,%d,%d) => %d', v, min, max, wrapf( v, min, max ) );
34-
}
32+
logEachMap( 'wrapf(%0.4f,%0.4f,%0.4f) => %0.4f', v, min, max, wrapf );

lib/node_modules/@stdlib/math/base/special/wrapf/include/stdlib/math/base/special/wrapf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* Wraps a value on the half-open interval [min,max) for single-precision floating-point numbers.
30+
* Wraps a single-precision floating-point value to the half-open interval [min,max).
3131
*/
3232
float stdlib_base_wrapf( const float v, const float min, const float max );
3333

lib/node_modules/@stdlib/math/base/special/wrapf/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Wrap a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
22+
* Wrap a single-precision floating-point value to the half-open interval `[min,max)`.
2323
*
2424
* @module @stdlib/math/base/special/wrapf
2525
*

lib/node_modules/@stdlib/math/base/special/wrapf/lib/main.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@
2222

2323
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2424
var truncf = require( '@stdlib/math/base/special/truncf' );
25-
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
25+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
26+
27+
28+
// VARIABLES //
29+
30+
var ZERO = f32( 0.0 );
31+
var ONE = f32( 1.0 );
2632

2733

2834
// MAIN //
2935

3036
/**
31-
* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
37+
* Wraps a single-precision floating-point value to the half-open interval `[min,max)`.
3238
*
3339
* @param {number} v - input value
3440
* @param {number} min - minimum value
@@ -65,6 +71,10 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
6571
*/
6672
function wrapf( v, min, max ) {
6773
var delta;
74+
75+
v = f32( v );
76+
min = f32( min );
77+
max = f32( max );
6878
if (
6979
isnanf( v ) ||
7080
isnanf( min ) ||
@@ -73,29 +83,26 @@ function wrapf( v, min, max ) {
7383
) {
7484
return NaN;
7585
}
76-
7786
// Normalize +-0 to +0...
7887
if ( v === 0.0 ) {
79-
v = 0.0;
88+
v = ZERO;
8089
}
8190
if ( min === 0.0 ) {
82-
min = 0.0;
91+
min = ZERO;
8392
}
8493
if ( max === 0.0 ) {
85-
max = 0.0;
94+
max = ZERO;
8695
}
87-
8896
// Simple case where value is already within range...
8997
if ( min <= v && v < max ) {
90-
return float64ToFloat32( v );
98+
return v;
9199
}
92-
93100
// Perform range reduction...
94-
delta = max - min;
101+
delta = f32( max - min );
95102
if ( v < min ) {
96-
v += delta * ( truncf( ( min - v ) / delta ) + 1.0 );
103+
v = f32( v + f32( delta * f32( truncf( f32(min-v) / f32(delta) ) + ONE ) ) );
97104
}
98-
return float64ToFloat32( float64ToFloat32( min ) + float64ToFloat32( float64ToFloat32( float64ToFloat32( v ) - float64ToFloat32( min ) ) % float64ToFloat32( delta ) ) );
105+
return f32( min + f32( f32( v-min ) % delta ) );
99106
}
100107

101108

lib/node_modules/@stdlib/math/base/special/wrapf/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Wraps a value on the half-open interval `[min,max)` for single-precision floating-point numbers.
29+
* Wraps a single-precision floating-point value to the half-open interval `[min,max)`.
3030
*
3131
* @private
3232
* @param {number} v - input value

lib/node_modules/@stdlib/math/base/special/wrapf/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/math/base/special/wrapf",
33
"version": "0.0.0",
4-
"description": "Wrap a value on the half-open interval [min,max) for single-precision floating-point numbers",
4+
"description": "Wrap a single-precision floating-point value to the half-open interval [min,max).",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",
@@ -57,6 +57,7 @@
5757
"mathematics",
5858
"math",
5959
"wrap",
60+
"wrapf",
6061
"modulo",
6162
"mod",
6263
"range",

lib/node_modules/@stdlib/math/base/special/wrapf/src/addon.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919
#include "stdlib/math/base/special/wrapf.h"
2020
#include "stdlib/math/base/napi/ternary.h"
2121

22-
// cppcheck-suppress shadowFunction
2322
STDLIB_MATH_BASE_NAPI_MODULE_FFF_F( stdlib_base_wrapf )

lib/node_modules/@stdlib/math/base/special/wrapf/src/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
#include "stdlib/math/base/special/truncf.h"
2222
#include "stdlib/math/base/special/fmodf.h"
2323
#include "stdlib/math/base/assert/is_negative_zerof.h"
24-
#include <math.h>
2524

2625
/**
27-
* Wraps a value on the half-open interval [min,max) for single-precision floating-point numbers.
26+
* Wraps a single-precision floating-point value to the half-open interval [min,max).
2827
*
2928
* @param v input value
3029
* @param min minimum value
@@ -33,7 +32,7 @@
3332
*
3433
* @example
3534
* float v = stdlib_base_wrapf( 3.14f, 0.0f, 5.0f );
36-
* // returns ~3.14
35+
* // returns ~3.14f
3736
*/
3837
float stdlib_base_wrapf( const float v, const float min, const float max ) {
3938
float delta;
@@ -58,12 +57,10 @@ float stdlib_base_wrapf( const float v, const float min, const float max ) {
5857
if ( stdlib_base_is_negative_zerof( maxc ) ) {
5958
maxc = 0.0f;
6059
}
61-
6260
// Simple case where value is already within range...
6361
if ( minc <= vc && vc < maxc ) {
6462
return vc;
6563
}
66-
6764
// Perform range reduction...
6865
delta = maxc - minc;
6966
if ( vc < minc ) {

0 commit comments

Comments
 (0)