diff options
Diffstat (limited to '')
-rw-r--r-- | src/options.cpp | 2 | ||||
-rw-r--r-- | src/packedintarray.cpp | 7 | ||||
-rw-r--r-- | src/unitnumber.cpp | 14 | ||||
-rw-r--r-- | src/unitnumber.h | 1 |
4 files changed, 18 insertions, 6 deletions
diff --git a/src/options.cpp b/src/options.cpp index 89397f4..4fcf1e2 100644 --- a/src/options.cpp +++ b/src/options.cpp | |||
@@ -17,7 +17,7 @@ Options::~Options() | |||
17 | { | 17 | { |
18 | } | 18 | } |
19 | 19 | ||
20 | int Options::selfTest( Bu::StringArray aArgs ) | 20 | int Options::selfTest( Bu::StringArray ) |
21 | { | 21 | { |
22 | UnitNumber().run(); | 22 | UnitNumber().run(); |
23 | 23 | ||
diff --git a/src/packedintarray.cpp b/src/packedintarray.cpp index b91358e..824f589 100644 --- a/src/packedintarray.cpp +++ b/src/packedintarray.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | #define bitsizeof( x ) ((sizeof(x))*8) | 5 | #define bitsizeof( x ) ((sizeof(x))*8) |
6 | #define StoreBits ((bitsizeof(PackedIntArray::Store))) | 6 | #define StoreBits ((bitsizeof(PackedIntArray::Store))) |
7 | #define StoreCount( x ) (((x*iBitWidth)/StoreBits)+(((x*iBitWidth)%StoreBits)?1:0)) | 7 | #define StoreCount( x ) ((((x)*iBitWidth)/StoreBits)+((((x)*iBitWidth)%StoreBits)?1:0)) |
8 | 8 | ||
9 | PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth ) : | 9 | PackedIntArray::PackedIntArray( PackedIntArray::Unit iBitWidth ) : |
10 | iBitWidth( iBitWidth ), | 10 | iBitWidth( iBitWidth ), |
@@ -207,10 +207,11 @@ void PackedIntArray::checkCapacity() | |||
207 | { | 207 | { |
208 | // Bu::println("!!! Resizing !!!"); | 208 | // Bu::println("!!! Resizing !!!"); |
209 | Store *aOldData = aData; | 209 | Store *aOldData = aData; |
210 | int iSize = StoreCount(iCapacity); | ||
210 | int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2)); | 211 | int iNewSize = (iCapacity==0)?(bitsizeof(Store)/iBitWidth):(iCapacity=StoreCount(iCapacity*2)); |
211 | while( iNewSize < iCount ) | 212 | int iCountSize = StoreCount(iCount); |
213 | while( iNewSize < iCountSize ) | ||
212 | iNewSize *= 2; | 214 | iNewSize *= 2; |
213 | int iSize = StoreCount(iCapacity); | ||
214 | // Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) | 215 | // Bu::println(" %1 => %2 (%3 bit words)").arg( iSize ).arg( iNewSize ) |
215 | // .arg( StoreBits ); | 216 | // .arg( StoreBits ); |
216 | aData = new Store[iNewSize]; | 217 | aData = new Store[iNewSize]; |
diff --git a/src/unitnumber.cpp b/src/unitnumber.cpp index d4bc7a8..79797c9 100644 --- a/src/unitnumber.cpp +++ b/src/unitnumber.cpp | |||
@@ -5,6 +5,8 @@ | |||
5 | UnitNumber::UnitNumber() | 5 | UnitNumber::UnitNumber() |
6 | { | 6 | { |
7 | setName("Number"); | 7 | setName("Number"); |
8 | add( static_cast<Bu::UnitSuite::Test>(&UnitNumber::parse1), | ||
9 | "parse1", Bu::UnitSuite::expectPass ); | ||
8 | add( static_cast<Bu::UnitSuite::Test>(&UnitNumber::multiply1), | 10 | add( static_cast<Bu::UnitSuite::Test>(&UnitNumber::multiply1), |
9 | "multiply1", Bu::UnitSuite::expectPass ); | 11 | "multiply1", Bu::UnitSuite::expectPass ); |
10 | } | 12 | } |
@@ -13,10 +15,18 @@ UnitNumber::~UnitNumber() | |||
13 | { | 15 | { |
14 | } | 16 | } |
15 | 17 | ||
18 | void UnitNumber::parse1() | ||
19 | { | ||
20 | unitTest( Number("121932631356500531347203169112635269").toString() == | ||
21 | "121932631356500531347203169112635269" ); | ||
22 | } | ||
23 | |||
16 | void UnitNumber::multiply1() | 24 | void UnitNumber::multiply1() |
17 | { | 25 | { |
26 | unitTest(Number("123456789") * Number("987654321") == "121932631112635269"); | ||
18 | unitTest( | 27 | unitTest( |
19 | (Number("123456789123456789") * Number("987654321987654321")).toString() | 28 | Number("123456789123456789") * Number("987654321987654321") == |
20 | == "121932631356500531347203169112635269" ); | 29 | "121932631356500531347203169112635269" |
30 | ); | ||
21 | } | 31 | } |
22 | 32 | ||
diff --git a/src/unitnumber.h b/src/unitnumber.h index 89b1c0f..76496b9 100644 --- a/src/unitnumber.h +++ b/src/unitnumber.h | |||
@@ -9,6 +9,7 @@ public: | |||
9 | UnitNumber(); | 9 | UnitNumber(); |
10 | virtual ~UnitNumber(); | 10 | virtual ~UnitNumber(); |
11 | 11 | ||
12 | void parse1(); | ||
12 | void multiply1(); | 13 | void multiply1(); |
13 | }; | 14 | }; |
14 | 15 | ||