|
|
@ -321,7 +321,8 @@ void BigNum::DivNormalized (const BigNum & a, const BigNum & b, BigNum * remaind |
|
|
|
if (quotient) { |
|
|
|
if (quotient) { |
|
|
|
Val borrow = 0; |
|
|
|
Val borrow = 0; |
|
|
|
Val carry = 0; |
|
|
|
Val carry = 0; |
|
|
|
for (unsigned denomIndex = 0; denomIndex != denomCount; ++denomIndex) { |
|
|
|
unsigned denomIndex; |
|
|
|
|
|
|
|
for (denomIndex = 0; denomIndex != denomCount; ++denomIndex) { |
|
|
|
DVal product = (DVal)(Mul((*denom)[denomIndex], quotient) + carry); |
|
|
|
DVal product = (DVal)(Mul((*denom)[denomIndex], quotient) + carry); |
|
|
|
carry = HIGH(product); |
|
|
|
carry = HIGH(product); |
|
|
|
numer->SetVal(quotientIndex + denomIndex, (DVal)((DVal)(*numer)[quotientIndex + denomIndex] - (DVal)LOW(product) - (DVal)borrow), &borrow); |
|
|
|
numer->SetVal(quotientIndex + denomIndex, (DVal)((DVal)(*numer)[quotientIndex + denomIndex] - (DVal)LOW(product) - (DVal)borrow), &borrow); |
|
|
@ -1297,7 +1298,8 @@ void BigNum::Sub (const BigNum & a, Val b) { |
|
|
|
const unsigned count = a.Count(); |
|
|
|
const unsigned count = a.Count(); |
|
|
|
SetCount(count); |
|
|
|
SetCount(count); |
|
|
|
Val borrow = b; |
|
|
|
Val borrow = b; |
|
|
|
for (unsigned index = 0; index < count; ++index) { |
|
|
|
unsigned index; |
|
|
|
|
|
|
|
for (index = 0; index < count; ++index) { |
|
|
|
SetVal(index, (DVal)((DVal)a[index] - (DVal)borrow), &borrow); |
|
|
|
SetVal(index, (DVal)((DVal)a[index] - (DVal)borrow), &borrow); |
|
|
|
borrow = (Val)((Val)0 - (Val)borrow); |
|
|
|
borrow = (Val)((Val)0 - (Val)borrow); |
|
|
|
} |
|
|
|
} |
|
|
@ -1314,7 +1316,8 @@ void BigNum::Sub (const BigNum & a, const BigNum & b) { |
|
|
|
const unsigned bCount = b.Count(); |
|
|
|
const unsigned bCount = b.Count(); |
|
|
|
GrowToCount(count, true); |
|
|
|
GrowToCount(count, true); |
|
|
|
Val borrow = 0; |
|
|
|
Val borrow = 0; |
|
|
|
for (unsigned index = 0; index < count; ++index) { |
|
|
|
unsigned index; |
|
|
|
|
|
|
|
for (index = 0; index < count; ++index) { |
|
|
|
Val bVal = (index < bCount) ? b[index] : (Val)0; |
|
|
|
Val bVal = (index < bCount) ? b[index] : (Val)0; |
|
|
|
SetVal(index, (DVal)((DVal)a[index] - (DVal)bVal - (DVal)borrow), &borrow); |
|
|
|
SetVal(index, (DVal)((DVal)a[index] - (DVal)bVal - (DVal)borrow), &borrow); |
|
|
|
borrow = (Val)((Val)0 - (Val)borrow); |
|
|
|
borrow = (Val)((Val)0 - (Val)borrow); |
|
|
|