Skip to content

Commit afb9662

Browse files
Aadish JainAadish Jain
authored andcommitted
feat(special-wrapf): fixed test cases and style errors
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 7126246 commit afb9662

File tree

8 files changed

+28
-73
lines changed

8 files changed

+28
-73
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bench( pkg, function benchmark( b ) {
3636

3737
b.tic();
3838
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*20.0 ) - 10.0;
39+
x = ( randu() * 20.0 ) - 10.0;
4040
y = wrapf( x, -5.0, 5.0 );
4141
if ( isnan( y ) ) {
4242
b.fail( 'should not return NaN' );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4545

4646
b.tic();
4747
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*20.0 ) - 10.0;
48+
x = ( randu() * 20.0 ) - 10.0;
4949
y = wrapf( x, -5.0, 5.0 );
5050
if ( isnan( y ) ) {
5151
b.fail( 'should not return NaN' );

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void print_results( float elapsed ) {
7070
static float tic( void ) {
7171
struct timeval now;
7272
gettimeofday( &now, NULL );
73-
return (float)now.tv_sec + (float)now.tv_usec/1.0e6;
73+
return (float)now.tv_sec + (float)now.tv_usec / 1.0e6;
7474
}
7575

7676
/**
@@ -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 * ( trunc( (min-v)/delta ) + 1.0 );
102+
v += delta * ( trunc( ( min - v ) / delta ) + 1.0 );
103103
}
104-
return min + fmod( (v-min), delta );
104+
return min + fmod( ( v - min ), delta );
105105
}
106106

107107
/**
@@ -118,7 +118,7 @@ static float benchmark( void ) {
118118

119119
t = tic();
120120
for ( i = 0; i < ITERATIONS; i++ ) {
121-
x = ( 20.0*rand_float() ) - 10.0;
121+
x = ( 20.0 * rand_float() ) - 10.0;
122122
y = wrapf( x, -5.0, 5.0 );
123123
if ( y != y ) {
124124
printf( "should not return NaN\n" );

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
@@ -71,7 +71,7 @@ static void print_results( float elapsed ) {
7171
static float tic( void ) {
7272
struct timeval now;
7373
gettimeofday( &now, NULL );
74-
return (float)now.tv_sec + (float)now.tv_usec/1.0e6;
74+
return (float)now.tv_sec + (float)now.tv_usec / 1.0e6;
7575
}
7676

7777
/**
@@ -98,7 +98,7 @@ static float benchmark( void ) {
9898

9999
t = tic();
100100
for ( i = 0; i < ITERATIONS; i++ ) {
101-
x = ( 20.0*rand_float() ) - 10.0;
101+
x = ( 20.0 * rand_float() ) - 10.0;
102102
y = stdlib_base_wrapf( x, -5.0, 5.0 );
103103
if ( y != y ) {
104104
printf( "should not return NaN\n" );
@@ -127,7 +127,7 @@ int main( void ) {
127127
printf( "# c::%s\n", NAME );
128128
elapsed = benchmark();
129129
print_results( elapsed );
130-
printf( "ok %d benchmark finished\n", i+1 );
130+
printf( "ok %d benchmark finished\n", i + 1 );
131131
}
132132
print_summary( REPEATS, REPEATS );
133133
}

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/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* var wrapf = require( '@stdlib/math/base/special/wrapf' );
2828
*
2929
* var v = wrapf( 3.14, 0.0, 5.0 );
30-
* // returns 3.14
30+
* // returns ~3.14
3131
*
3232
* v = wrapf( -3.14, 0.0, 5.0 );
3333
* // returns ~1.86

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

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2018 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.
@@ -76,8 +76,9 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma
7676
} else {
7777
delta = abs( v - expected );
7878
tol = EPS * abs( expected );
79-
t.equal( delta <= tol, true, 'within tolerance. v: '+v+'. expected: '+expected+'. Δ: '+delta+'. tol: '+tol+'.' );
79+
t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
8080
}
81+
8182
expected = -3.14;
8283
v = wrapf( -3.14, -10.0, 15.0 );
8384
if ( v === expected ) {
@@ -87,6 +88,7 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma
8788
tol = EPS * abs( expected );
8889
t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
8990
}
91+
9092
expected = 3.14;
9193
v = wrapf( 3.14, 3.14, 5.0 );
9294
if ( v === expected ) {
@@ -96,6 +98,7 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma
9698
tol = EPS * abs( expected );
9799
t.equal( delta <= tol, true, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
98100
}
101+
99102
expected = 3.13;
100103
v = wrapf( 3.13, 0.0, 3.14 );
101104
if ( v === expected ) {
@@ -110,33 +113,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma
110113
});
111114

112115
tape( 'if provided a value which less than a minimum value or greater than or equal to a maximum value, the function wraps the value using modulo arithmetic', function test( t ) {
113-
var expected;
114-
var delta;
115-
var tol;
116116
var v;
117117

118118
v = wrapf( 13.00, 0.0, 5.0 );
119119
t.strictEqual( v, 3.00, 'returns expected value' );
120120

121-
expected = 1.85;
122-
v = wrapf( -3.15, 0.0, 5.0 );
123-
if ( v === expected ) {
124-
t.equal( v, expected, 'returns expected value' );
125-
} else {
126-
delta = abs( v - expected );
127-
tol = EPS * abs( expected );
128-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
129-
}
121+
v = wrapf( -3.0, 0.0, 5.0 );
122+
t.strictEqual( v, 2.0, 'returns expected value' );
130123

131-
expected = 11.86;
132-
v = wrapf( -13.14, -10.0, 15.0 );
133-
if ( v === expected ) {
134-
t.equal( v, expected, 'returns expected value' );
135-
} else {
136-
delta = abs( v - expected );
137-
tol = EPS * abs( expected );
138-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
139-
}
124+
v = wrapf( -13.0, -10.0, 15.0 );
125+
t.strictEqual( v, 12.0, 'returns expected value' );
140126

141127
v = wrapf( 10.0, 0.0, 5.0 );
142128
t.strictEqual( v, 0.0, 'returns expected value' );
@@ -159,15 +145,8 @@ tape( 'if provided a value which less than a minimum value or greater than or eq
159145
v = wrapf( -31.0, -5.0, 0.0 );
160146
t.strictEqual( v, -1.0, 'returns expected value' );
161147

162-
expected = -3.14;
163-
v = wrapf( 0.0, -3.14, 0.0 );
164-
if ( v === expected ) {
165-
t.equal( v, expected, 'returns expected value' );
166-
} else {
167-
delta = abs( v - expected );
168-
tol = EPS * abs( expected );
169-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
170-
}
148+
v = wrapf( 0.0, -3.0, 0.0 );
149+
t.strictEqual( v, -3.0, 'returns expected value' );
171150

172151
v = wrapf( 0.0, -10.0, -0.0 );
173152
t.strictEqual( v, -10.0, 'returns expected value' );

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,33 +119,16 @@ tape( 'if provided a value which is between a minimum value (inclusive) and a ma
119119
});
120120

121121
tape( 'if provided a value which less than a minimum value or greater than or equal to a maximum value, the function wraps the value using modulo arithmetic', opts, function test( t ) {
122-
var expected;
123-
var delta;
124-
var tol;
125122
var v;
126123

127124
v = wrapf( 13.00, 0.0, 5.0 );
128125
t.strictEqual( v, 3.00, 'returns expected value' );
129126

130-
expected = 1.85;
131-
v = wrapf( -3.15, 0.0, 5.0 );
132-
if ( v === expected ) {
133-
t.equal( v, expected, 'returns expected value' );
134-
} else {
135-
delta = abs( v - expected );
136-
tol = EPS * abs( expected );
137-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
138-
}
127+
v = wrapf( -3.0, 0.0, 5.0 );
128+
t.strictEqual( v, 2.0, 'returns expected value' );
139129

140-
expected = 11.86;
141-
v = wrapf( -13.14, -10.0, 15.0 );
142-
if ( v === expected ) {
143-
t.equal( v, expected, 'returns expected value' );
144-
} else {
145-
delta = abs( v - expected );
146-
tol = EPS * abs( expected );
147-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
148-
}
130+
v = wrapf( -13.0, -10.0, 15.0 );
131+
t.strictEqual( v, 12.0, 'returns expected value' );
149132

150133
v = wrapf( 10.0, 0.0, 5.0 );
151134
t.strictEqual( v, 0.0, 'returns expected value' );
@@ -168,15 +151,8 @@ tape( 'if provided a value which less than a minimum value or greater than or eq
168151
v = wrapf( -31.0, -5.0, 0.0 );
169152
t.strictEqual( v, -1.0, 'returns expected value' );
170153

171-
expected = -3.14;
172-
v = wrapf( 0.0, -3.14, 0.0 );
173-
if ( v === expected ) {
174-
t.equal( v, expected, 'returns expected value' );
175-
} else {
176-
delta = abs( v - expected );
177-
tol = EPS * abs( expected );
178-
t.ok( delta <= tol, 'within tolerance. v: ' + v + '. expected: ' + expected + '. Δ: ' + delta + '. tol: ' + tol + '.' );
179-
}
154+
v = wrapf( 0.0, -3.0, 0.0 );
155+
t.strictEqual( v, -3.0, 'returns expected value' );
180156

181157
v = wrapf( 0.0, -10.0, -0.0 );
182158
t.strictEqual( v, -10.0, 'returns expected value' );

0 commit comments

Comments
 (0)