From c17afa550d0a00498301454195699120e2bf58c5 Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Sun, 3 May 2009 16:53:39 -0400 Subject: [PATCH] BigUnsigned::{get,set}Bit: Change two `1 <<' to `Blk(1) <<'. Bug reported by Brad Spencer. --- BigUnsigned.cc | 2 +- BigUnsigned.hh | 2 +- ChangeLog | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BigUnsigned.cc b/BigUnsigned.cc index ffb6c6c..d7f9889 100644 --- a/BigUnsigned.cc +++ b/BigUnsigned.cc @@ -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); } diff --git a/BigUnsigned.hh b/BigUnsigned.hh index 683ac8b..adf1c00 100644 --- a/BigUnsigned.hh +++ b/BigUnsigned.hh @@ -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. */ diff --git a/ChangeLog b/ChangeLog index 0f87898..abca677 100644 --- 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. -- 2.34.1