Skip to content

Commit 4b70b76

Browse files
fix: ulpdiff implemntation in test.js and test.native.js
--- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - 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 07705bf commit 4b70b76

File tree

2 files changed

+38
-144
lines changed

2 files changed

+38
-144
lines changed

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

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ var tape = require( 'tape' );
2424
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2525
var PINF = require( '@stdlib/constants/float32/pinf' );
2626
var NINF = require( '@stdlib/constants/float32/ninf' );
27-
var EPS = require( '@stdlib/constants/float32/eps' );
28-
var abs = require( '@stdlib/math/base/special/abs' );
2927
var f32 = require( '@stdlib/number/float64/base/to-float32' );
3028
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3129
var ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' );
3230
var log10f = require( './../lib' );
31+
32+
33+
// FIXTURES //
34+
3335
var veryLargePositive = require( './fixtures/julia/very_large_positive.json' );
3436
var largePositive = require( './fixtures/julia/large_positive.json' );
3537
var mediumPositive = require( './fixtures/julia/medium_positive.json' );
@@ -49,8 +51,6 @@ tape( 'main export is a function', function test( t ) {
4951

5052
tape( 'the function evaluates the common logarithm of `x` (very large positive values)', function test( t ) {
5153
var expected;
52-
var delta;
53-
var tol;
5454
var x;
5555
var y;
5656
var i;
@@ -59,23 +59,15 @@ tape( 'the function evaluates the common logarithm of `x` (very large positive v
5959
expected = veryLargePositive.expected;
6060
x = veryLargePositive.x;
6161
for ( i = 0; i < x.length; i++ ) {
62-
y = log10f( x[i] );
62+
y = log10f( x[ i ] );
6363
e = f32( expected[ i ] );
64-
if ( y === e ) {
65-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
66-
} else {
67-
delta = abs( y - e );
68-
tol = EPS * abs( e );
69-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
70-
}
64+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
7165
}
7266
t.end();
7367
});
7468

7569
tape( 'the function evaluates the common logarithm of `x` (large positive values)', function test( t ) {
7670
var expected;
77-
var delta;
78-
var tol;
7971
var x;
8072
var y;
8173
var i;
@@ -84,23 +76,15 @@ tape( 'the function evaluates the common logarithm of `x` (large positive values
8476
expected = largePositive.expected;
8577
x = largePositive.x;
8678
for ( i = 0; i < x.length; i++ ) {
87-
y = log10f( x[i] );
79+
y = log10f( x[ i ] );
8880
e = f32( expected[ i ] );
89-
if ( y === e ) {
90-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
91-
} else {
92-
delta = abs( y - e );
93-
tol = EPS * abs( e );
94-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
95-
}
81+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
9682
}
9783
t.end();
9884
});
9985

10086
tape( 'the function evaluates the common logarithm of `x` (medium positive values)', function test( t ) {
10187
var expected;
102-
var delta;
103-
var tol;
10488
var x;
10589
var y;
10690
var i;
@@ -109,23 +93,15 @@ tape( 'the function evaluates the common logarithm of `x` (medium positive value
10993
expected = mediumPositive.expected;
11094
x = mediumPositive.x;
11195
for ( i = 0; i < x.length; i++ ) {
112-
y = log10f( x[i] );
96+
y = log10f( x[ i ] );
11397
e = f32( expected[ i ] );
114-
if ( y === e ) {
115-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
116-
} else {
117-
delta = abs( y - e );
118-
tol = EPS * abs( e );
119-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
120-
}
98+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
12199
}
122100
t.end();
123101
});
124102

125103
tape( 'the function evaluates the common logarithm of `x` (small positive values)', function test( t ) {
126104
var expected;
127-
var delta;
128-
var tol;
129105
var x;
130106
var y;
131107
var i;
@@ -134,23 +110,15 @@ tape( 'the function evaluates the common logarithm of `x` (small positive values
134110
expected = smallPositive.expected;
135111
x = smallPositive.x;
136112
for ( i = 0; i < x.length; i++ ) {
137-
y = log10f( x[i] );
113+
y = log10f( x[ i ] );
138114
e = f32( expected[ i ] );
139-
if ( y === e ) {
140-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
141-
} else {
142-
delta = abs( y - e );
143-
tol = ulpdiff( y, e );
144-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
145-
}
115+
t.strictEqual( ulpdiff( y, e ) <= 152, true, 'returns expected value' );
146116
}
147117
t.end();
148118
});
149119

150120
tape( 'the function evaluates the common logarithm of `x` (smaller positive values)', function test( t ) {
151121
var expected;
152-
var delta;
153-
var tol;
154122
var x;
155123
var y;
156124
var i;
@@ -159,23 +127,15 @@ tape( 'the function evaluates the common logarithm of `x` (smaller positive valu
159127
expected = smaller.expected;
160128
x = smaller.x;
161129
for ( i = 0; i < x.length; i++ ) {
162-
y = log10f( x[i] );
130+
y = log10f( x[ i ] );
163131
e = f32( expected[ i ] );
164-
if ( y === e ) {
165-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
166-
} else {
167-
delta = abs( y - e );
168-
tol = 1.8 * EPS * abs( e );
169-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
170-
}
132+
t.strictEqual( ulpdiff( y, e ) <= 8, true, 'returns expected value' );
171133
}
172134
t.end();
173135
});
174136

175137
tape( 'the function evaluates the common logarithm of `x` (tiny positive values)', function test( t ) {
176138
var expected;
177-
var delta;
178-
var tol;
179139
var x;
180140
var y;
181141
var i;
@@ -184,23 +144,15 @@ tape( 'the function evaluates the common logarithm of `x` (tiny positive values)
184144
expected = tinyPositive.expected;
185145
x = tinyPositive.x;
186146
for ( i = 0; i < x.length; i++ ) {
187-
y = log10f( x[i] );
147+
y = log10f( x[ i ] );
188148
e = f32( expected[ i ] );
189-
if ( y === e ) {
190-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
191-
} else {
192-
delta = abs( y - e );
193-
tol = EPS * abs( e );
194-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
195-
}
149+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
196150
}
197151
t.end();
198152
});
199153

200154
tape( 'the function evaluates the common logarithm of `x` (subnormal values)', function test( t ) {
201155
var expected;
202-
var delta;
203-
var tol;
204156
var x;
205157
var y;
206158
var i;
@@ -209,15 +161,9 @@ tape( 'the function evaluates the common logarithm of `x` (subnormal values)', f
209161
expected = subnormal.expected;
210162
x = subnormal.x;
211163
for ( i = 0; i < x.length; i++ ) {
212-
y = log10f( x[i] );
164+
y = log10f( x[ i ] );
213165
e = f32( expected[ i ] );
214-
if ( y === e ) {
215-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
216-
} else {
217-
delta = abs( y - e );
218-
tol = 7.0 * EPS * abs( e );
219-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
220-
}
166+
t.strictEqual( ulpdiff( y, e ) <= 9, true, 'returns expected value' );
221167
}
222168
t.end();
223169
});

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

Lines changed: 20 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ var tape = require( 'tape' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var PINF = require( '@stdlib/constants/float32/pinf' );
2727
var NINF = require( '@stdlib/constants/float32/ninf' );
28-
var EPS = require( '@stdlib/constants/float32/eps' );
29-
var abs = require( '@stdlib/math/base/special/abs' );
3028
var f32 = require( '@stdlib/number/float64/base/to-float32' );
3129
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3230
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -62,8 +60,6 @@ tape( 'main export is a function', opts, function test( t ) {
6260

6361
tape( 'the function evaluates the common logarithm of `x` (very large positive values)', opts, function test( t ) {
6462
var expected;
65-
var delta;
66-
var tol;
6763
var x;
6864
var y;
6965
var i;
@@ -73,23 +69,15 @@ tape( 'the function evaluates the common logarithm of `x` (very large positive v
7369
x = veryLargePositive.x;
7470
for ( i = 0; i < x.length; i++ ) {
7571
x[ i ] = f32( x[ i ]);
76-
y = log10f( x[i] );
72+
y = log10f( x[ i ] );
7773
e = f32( expected[ i ] );
78-
if ( y === e ) {
79-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
80-
} else {
81-
delta = abs( y - e );
82-
tol = EPS * abs( e );
83-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
84-
}
74+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
8575
}
8676
t.end();
8777
});
8878

8979
tape( 'the function evaluates the common logarithm of `x` (large positive values)', opts, function test( t ) {
9080
var expected;
91-
var delta;
92-
var tol;
9381
var x;
9482
var y;
9583
var i;
@@ -98,23 +86,16 @@ tape( 'the function evaluates the common logarithm of `x` (large positive values
9886
expected = largePositive.expected;
9987
x = largePositive.x;
10088
for ( i = 0; i < x.length; i++ ) {
101-
y = log10f( x[i] );
89+
x[ i ] = f32( x[ i ]);
90+
y = log10f( x[ i ] );
10291
e = f32( expected[ i ] );
103-
if ( y === e ) {
104-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
105-
} else {
106-
delta = abs( y - e );
107-
tol = EPS * abs( e );
108-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
109-
}
92+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
11093
}
11194
t.end();
11295
});
11396

11497
tape( 'the function evaluates the common logarithm of `x` (medium positive values)', opts, function test( t ) {
11598
var expected;
116-
var delta;
117-
var tol;
11899
var x;
119100
var y;
120101
var i;
@@ -123,23 +104,16 @@ tape( 'the function evaluates the common logarithm of `x` (medium positive value
123104
expected = mediumPositive.expected;
124105
x = mediumPositive.x;
125106
for ( i = 0; i < x.length; i++ ) {
126-
y = log10f( x[i] );
107+
x[ i ] = f32( x[ i ]);
108+
y = log10f( x[ i ] );
127109
e = f32( expected[ i ] );
128-
if ( y === e ) {
129-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
130-
} else {
131-
delta = abs( y - e );
132-
tol = EPS * abs( e );
133-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
134-
}
110+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
135111
}
136112
t.end();
137113
});
138114

139115
tape( 'the function evaluates the common logarithm of `x` (small positive values)', opts, function test( t ) {
140116
var expected;
141-
var delta;
142-
var tol;
143117
var x;
144118
var y;
145119
var i;
@@ -148,23 +122,16 @@ tape( 'the function evaluates the common logarithm of `x` (small positive values
148122
expected = smallPositive.expected;
149123
x = smallPositive.x;
150124
for ( i = 0; i < x.length; i++ ) {
151-
y = log10f( x[i] );
125+
x[ i ] = f32( x[ i ]);
126+
y = log10f( x[ i ] );
152127
e = f32( expected[ i ] );
153-
if ( y === e ) {
154-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
155-
} else {
156-
delta = abs( y - e );
157-
tol = ulpdiff( y, e );
158-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
159-
}
128+
t.strictEqual( ulpdiff( y, e ) <= 152, true, 'returns expected value' );
160129
}
161130
t.end();
162131
});
163132

164133
tape( 'the function evaluates the common logarithm of `x` (smaller positive values)', opts, function test( t ) {
165134
var expected;
166-
var delta;
167-
var tol;
168135
var x;
169136
var y;
170137
var i;
@@ -173,23 +140,16 @@ tape( 'the function evaluates the common logarithm of `x` (smaller positive valu
173140
expected = smaller.expected;
174141
x = smaller.x;
175142
for ( i = 0; i < x.length; i++ ) {
176-
y = log10f( x[i] );
143+
x[ i ] = f32( x[ i ]);
144+
y = log10f( x[ i ] );
177145
e = f32( expected[ i ] );
178-
if ( y === e ) {
179-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
180-
} else {
181-
delta = abs( y - e );
182-
tol = 2.0 * EPS * abs( e );
183-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
184-
}
146+
t.strictEqual( ulpdiff( y, e ) <= 8, true, 'returns expected value' );
185147
}
186148
t.end();
187149
});
188150

189151
tape( 'the function evaluates the common logarithm of `x` (tiny positive values)', opts, function test( t ) {
190152
var expected;
191-
var delta;
192-
var tol;
193153
var x;
194154
var y;
195155
var i;
@@ -198,23 +158,16 @@ tape( 'the function evaluates the common logarithm of `x` (tiny positive values)
198158
expected = tinyPositive.expected;
199159
x = tinyPositive.x;
200160
for ( i = 0; i < x.length; i++ ) {
201-
y = log10f( x[i] );
161+
x[ i ] = f32( x[ i ]);
162+
y = log10f( x[ i ] );
202163
e = f32( expected[ i ] );
203-
if ( y === e ) {
204-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
205-
} else {
206-
delta = abs( y - e );
207-
tol = EPS * abs( e );
208-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
209-
}
164+
t.strictEqual( ulpdiff( y, e ) <= 1, true, 'returns expected value' );
210165
}
211166
t.end();
212167
});
213168

214169
tape( 'the function evaluates the common logarithm of `x` (subnormal values)', opts, function test( t ) {
215170
var expected;
216-
var delta;
217-
var tol;
218171
var x;
219172
var y;
220173
var i;
@@ -223,15 +176,10 @@ tape( 'the function evaluates the common logarithm of `x` (subnormal values)', o
223176
expected = subnormal.expected;
224177
x = subnormal.x;
225178
for ( i = 0; i < x.length; i++ ) {
226-
y = log10f( x[i] );
179+
x[ i ] = f32( x[ i ]);
180+
y = log10f( x[ i ] );
227181
e = f32( expected[ i ] );
228-
if ( y === e ) {
229-
t.strictEqual( y, e, 'x: '+x[i]+', y: '+y+', expected: '+e );
230-
} else {
231-
delta = abs( y - e );
232-
tol = 7.0 * EPS * abs( e );
233-
t.strictEqual( delta <= tol, true, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+e+'. Δ: '+delta+'. Tolerance: '+tol+'.' );
234-
}
182+
t.strictEqual( ulpdiff( y, e ) <= 9, true, 'returns expected value' );
235183
}
236184
t.end();
237185
});

0 commit comments

Comments
 (0)