Skip to content

Commit e8bffef

Browse files
refactor: move isnan check from assign.js into main.js and utilize umul
--- 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: 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 2b1e266 commit e8bffef

3 files changed

Lines changed: 7 additions & 35 deletions

File tree

lib/node_modules/@stdlib/number/uint32/base/muldw/lib/assign.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// MODULES //
2222

23-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
23+
var umul = require( '@stdlib/number/uint32/base/mul' );
2424

2525

2626
// VARIABLES //
@@ -49,19 +49,13 @@ var LOW_WORD_MASK = 0x0000ffff>>>0; // asm type annotation
4949
function umuldw(a, b, out, stride, offset ) {
5050
var w1;
5151
var w2;
52-
var w3;
5352
var ha;
5453
var hb;
5554
var la;
5655
var lb;
5756
var t;
5857
var k;
5958

60-
if ( isnan( a ) || isnan( b ) ) {
61-
out[ offset ] = NaN;
62-
out[ offset + stride ] = NaN;
63-
return out;
64-
}
6559
a >>>= 0; // asm type annotation
6660
b >>>= 0; // asm type annotation
6761

@@ -72,7 +66,6 @@ function umuldw(a, b, out, stride, offset ) {
7266
lb = ( b & LOW_WORD_MASK ) >>> 0;
7367

7468
t = ( la*lb ) >>> 0;
75-
w3 = ( t & LOW_WORD_MASK ) >>> 0;
7669
k = ( t >>> 16 ) >>> 0;
7770

7871
t = ( ( ha*lb ) + k ) >>> 0;
@@ -83,7 +76,7 @@ function umuldw(a, b, out, stride, offset ) {
8376
k = ( t >>> 16 ) >>> 0;
8477

8578
out[ offset ] = ( ( ha*hb ) + w1 + k ) >>> 0; // compute the higher 32 bits and cast to an unsigned 32-bit integer
86-
out[ offset + stride ] = ( ( t << 16 ) + w3) >>> 0; // compute the lower 32 bits and cast to an unsigned 32-bit integer
79+
out[ offset + stride ] = umul(a, b) >>> 0; // compute the lower 32 bits and cast to an unsigned 32-bit integer
8780

8881
return out;
8982
}

lib/node_modules/@stdlib/number/uint32/base/muldw/lib/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2324
var fcn = require( './assign.js' );
2425

2526

@@ -37,6 +38,10 @@ var fcn = require( './assign.js' );
3738
* // returns [ 954437176, 1908874354 ]
3839
*/
3940
function umuldw( a, b ) {
41+
if ( isnan( a ) || isnan( b ) ) {
42+
return [ NaN, NaN ];
43+
}
44+
4045
return fcn( a, b, [ 0, 0 ], 1, 0 );
4146
}
4247

lib/node_modules/@stdlib/number/uint32/base/muldw/test/test.assign.js

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

2323
var tape = require( 'tape' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2524
var Float64Array = require( '@stdlib/array/float64' );
2625
var umuldw = require( './../lib/assign.js' );
2726

@@ -39,31 +38,6 @@ tape( 'main export is a function', function test( t ) {
3938
t.end();
4039
});
4140

42-
tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
43-
var out;
44-
var v;
45-
46-
out = [ 0, 0 ];
47-
v = umuldw( NaN, 1, out, 1, 0 );
48-
t.strictEqual( v, out, 'returns output array' );
49-
t.strictEqual( isnan( v[0] ), true, 'returns expected value' );
50-
t.strictEqual( isnan( v[1] ), true, 'returns expected value' );
51-
52-
out = [ 0, 0 ];
53-
v = umuldw( 1, NaN, out, 1, 0 );
54-
t.strictEqual( v, out, 'returns output array' );
55-
t.strictEqual( isnan( v[0] ), true, 'returns expected value' );
56-
t.strictEqual( isnan( v[1] ), true, 'returns expected value' );
57-
58-
out = [ 0, 0 ];
59-
v = umuldw( NaN, NaN, out, 1, 0 );
60-
t.strictEqual( v, out, 'returns output array' );
61-
t.strictEqual( isnan( v[0] ), true, 'returns expected value' );
62-
t.strictEqual( isnan( v[1] ), true, 'returns expected value' );
63-
64-
t.end();
65-
});
66-
6741
tape( 'the function computes the double word product of two (unsigned) words', function test( t ) {
6842
var expected;
6943
var actual;

0 commit comments

Comments
 (0)