BigUnsigned::{get,set}Bit: Change two `1 <<' to `Blk(1) <<'.
authorMatt McCutchen <matt@mattmccutchen.net>
Sun, 3 May 2009 20:53:39 +0000 (16:53 -0400)
committerMatt McCutchen <matt@mattmccutchen.net>
Sun, 3 May 2009 20:53:39 +0000 (16:53 -0400)
Bug reported by Brad Spencer.

BigUnsigned.cc
BigUnsigned.hh
ChangeLog

index ffb6c6c..d7f9889 100644 (file)
@@ -60,7 +60,7 @@ BigUnsigned::Index BigUnsigned::bitLength() const {
 
 void BigUnsigned::setBit(Index bi, bool newBit) {
        Index blockI = bi / N;
-       Blk block = getBlock(blockI), mask = 1 << (bi % N);
+       Blk block = getBlock(blockI), mask = Blk(1) << (bi % N);
        block = newBit ? (block | mask) : (block & ~mask);
        setBlock(blockI, block);
 }
index 683ac8b..adf1c00 100644 (file)
@@ -103,7 +103,7 @@ public:
        /* Get the state of bit bi, which has value 2^bi.  Bits beyond the
         * number's length are considered to be 0. */
        bool getBit(Index bi) const {
-               return (getBlock(bi / N) & (1 << (bi % N))) != 0;
+               return (getBlock(bi / N) & (Blk(1) << (bi % N))) != 0;
        }
        /* Sets the state of bit bi to newBit.  The number grows or shrinks as
         * necessary. */
index 0f87898..abca677 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,9 @@ same day.  The topmost version listed is the one you have.
 
 Unreleased
 ----------
+- BigUnsigned::{get,set}Bit: Change two remaining `1 <<' to `Blk(1) <<' to work
+  on systems where sizeof(unsigned int) != sizeof(Blk).  Bug reported by Brad
+  Spencer.
 - dataToBigInteger: Change a `delete' to `delete []' to avoid leaking memory.
   Bug reported by Nicolás Carrasco.
 
@@ -44,7 +47,7 @@ code that uses the library, but updating that code should be pretty easy:
 - The old {BigUnsigned,BigInteger}::{divide,modulo} copy-less options have been
   removed.  Use divideWithRemainder instead.
 - Added a base argument to BigUnsignedInABase's digit-array constructor.  I
-  hope no one used that constructor in its broken state anyway.
+  ope no one used that constructor in its broken state anyway.
 
 Other notable changes:
 - Added BigUnsigned functions setBlock, bitLength, getBit, setBit.