Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: BigInt.cpp
- Revision:
- 21:cfa04e0e6b59
- Parent:
- 20:d747159d77c4
- Child:
- 22:9d5f18b86753
diff -r d747159d77c4 -r cfa04e0e6b59 BigInt.cpp
--- a/BigInt.cpp Mon Mar 10 12:51:47 2014 +0000
+++ b/BigInt.cpp Mon Mar 10 13:25:33 2014 +0000
@@ -81,8 +81,8 @@
delete[] bits;
bits = new uint32_t[l];
memset(bits, 0, sizeof(uint32_t)*l);
- for(int i = length-1; i >=0; --i)
- bits[i/4] |= data[i] << ((i%4)*8);
+ for(int i = 0; i < length; ++i)
+ bits[(length-i-1)/4] |= data[i] << ((3-i%4)*8);
trim();
}
@@ -452,11 +452,10 @@
BigInt result;
- result.size = a.size < b.size ? a.size : b.size;
+ result.size = std::min(a.size, b.size);
uint32_t l = num(result.size);
result.bits = new uint32_t[l];
- memset(result.bits, 0, l);
-
+ memset(result.bits, 0, l*sizeof(uint32_t));
for(uint32_t i = 0; i < l; ++i)
result.bits[i] = a.bits[i] & b.bits[i];
@@ -480,8 +479,8 @@
uint32_t nb = num(b.size);
uint32_t l = std::max(na,nb);
result.size = std::max(a.size, b.size);
- result.bits = new uint32_t[l];
- memset(result.bits, 0, l);
+ result.bits = new uint32_t[num(result.size)];
+ memset(result.bits, 0, num(result.size)*sizeof(uint32_t));
for(uint32_t i = 0; i < l; ++i)
{
@@ -511,11 +510,10 @@
uint32_t na = num(a.size);
uint32_t nb = num(b.size);
- uint32_t l = std::max(na,nb);
result.size = std::max(a.size, b.size);
+ uint32_t l = num(result.size);
result.bits = new uint32_t[l];
- memset(result.bits, 0, l);
-
+ memset(result.bits, 0, l*sizeof(uint32_t));
for(uint32_t i = 0; i < l; ++i)
{
if(i < na && i < nb)