X-Git-Url: https://mattmccutchen.net/bigint/bigint.git/blobdiff_plain/8c16728a3d7689d8cc90028f5bc7cbf255b711d8..a8e1d2a44f8c5815d641a46caadf04c6ef732f45:/BigInteger.cc diff --git a/BigInteger.cc b/BigInteger.cc index ba49180..00074cf 100644 --- a/BigInteger.cc +++ b/BigInteger.cc @@ -311,7 +311,7 @@ BigInteger::CmpRes BigInteger::compareTo(const BigInteger &x) const { // then call one of BigUnsigned's put-heres. // See remarks about aliased calls in BigUnsigned.cc . -#define DOTR_ALIASED(cond, op) \ +#define DTRT_ALIASED(cond, op) \ if (cond) { \ BigInteger tmpThis; \ tmpThis.op; \ @@ -321,7 +321,7 @@ BigInteger::CmpRes BigInteger::compareTo(const BigInteger &x) const { // Addition void BigInteger::add(const BigInteger &a, const BigInteger &b) { - DOTR_ALIASED(this == &a || this == &b, add(a, b)); + DTRT_ALIASED(this == &a || this == &b, add(a, b)); // If one argument is zero, copy the other. if (a.sign == zero) operator =(b); @@ -358,7 +358,7 @@ void BigInteger::add(const BigInteger &a, const BigInteger &b) { void BigInteger::subtract(const BigInteger &a, const BigInteger &b) { // Notice that this routine is identical to BigInteger::add, // if one replaces b.sign by its opposite. - DOTR_ALIASED(this == &a || this == &b, subtract(a, b)); + DTRT_ALIASED(this == &a || this == &b, subtract(a, b)); // If a is zero, copy b and flip its sign. If b is zero, copy a. if (a.sign == zero) { BigUnsigned::operator =(b); @@ -397,7 +397,7 @@ void BigInteger::subtract(const BigInteger &a, const BigInteger &b) { // Multiplication void BigInteger::multiply(const BigInteger &a, const BigInteger &b) { - DOTR_ALIASED(this == &a || this == &b, multiply(a, b)); + DTRT_ALIASED(this == &a || this == &b, multiply(a, b)); // If one object is zero, copy zero and return. if (a.sign == zero || b.sign == zero) { sign = zero; @@ -443,7 +443,7 @@ void BigInteger::divideWithRemainder(const BigInteger &b, BigInteger &q) { divideWithRemainder(tmpB, q); return; } - + // Division by zero gives quotient 0 and remainder *this if (b.sign == zero) { q.len = 0; @@ -456,9 +456,9 @@ void BigInteger::divideWithRemainder(const BigInteger &b, BigInteger &q) { q.sign = zero; return; } - + // Here *this != 0, b != 0. - + // Do the operands have the same sign? if (sign == b.sign) { // Yes: easy case. Quotient is zero or positive. @@ -489,10 +489,10 @@ void BigInteger::divideWithRemainder(const BigInteger &b, BigInteger &q) { * Find r = (b - 1) - R and give it the desired sign. */ } - + // Divide the magnitudes. BigUnsigned::divideWithRemainder(b, q); - + if (sign != b.sign) { // More for the harder case (as described): // Increase the magnitude of the quotient by one. @@ -502,22 +502,22 @@ void BigInteger::divideWithRemainder(const BigInteger &b, BigInteger &q) { BigUnsigned::subtract(b, temp); BigUnsigned::operator --(); } - + // Sign of the remainder is always the sign of the divisor b. sign = b.sign; - + // Set signs to zero as necessary. (Thanks David Allen!) if (len == 0) sign = zero; if (q.len == 0) q.sign = zero; - + // WHEW!!! } // Negation void BigInteger::negate(const BigInteger &a) { - DOTR_ALIASED(this == &a, negate(a)); + DTRT_ALIASED(this == &a, negate(a)); // Copy a's magnitude BigUnsigned::operator =(a); // Copy the opposite of a.sign