mirror of
https://github.com/Michaelangel007/apple2_russian_peasant_multiplication.git
synced 2024-08-31 11:29:37 +00:00
Procedural Javascript - optimize Shr1()
This commit is contained in:
parent
2dbc120e02
commit
4f2d4af511
19
rpm_proc.js
19
rpm_proc.js
@ -156,17 +156,20 @@ function Shr1( array )
|
||||
var i;
|
||||
var n = array.length;
|
||||
var carry = 0;
|
||||
var q = 0;
|
||||
var div = 0;
|
||||
var rem = 0;
|
||||
var sum = 0;
|
||||
|
||||
for( i = n-1; i >= 0; --i )
|
||||
{
|
||||
div = array[ i ] + carry; // dividend
|
||||
q = (div / 2) | 0; // 2 is divisor
|
||||
array[i] = q;
|
||||
rem = div - q*2; // 2 is divisor
|
||||
carry = rem * BASE;
|
||||
// Optimized
|
||||
sum = array[i] + carry;
|
||||
array[i] = (sum / 2) | 0;
|
||||
carry = (sum & 1) ? BASE : 0;
|
||||
// Original
|
||||
// div = array[ i ] + carry; // dividend
|
||||
// q = (div / 2) | 0; // 2 is divisor
|
||||
// array[i] = q;
|
||||
// rem = div - q*2; // 2 is divisor
|
||||
// carry = rem * BASE;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user