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:
- 3:3fa3ceb0c69d
- Parent:
- 2:1001793a090d
- Child:
- 4:773aed3156c5
diff -r 1001793a090d -r 3fa3ceb0c69d BigInt.cpp
--- a/BigInt.cpp Fri Sep 20 15:50:25 2013 +0000
+++ b/BigInt.cpp Fri Sep 20 15:55:19 2013 +0000
@@ -127,20 +127,13 @@
BigInt& BigInt::operator++()
{
- uint8_t tmp = 1;
- BigInt a;
- a.import(&tmp, 1);
-
- return (*this += a);
+ return (*this += 1);
}
BigInt BigInt::operator++(int)
{
BigInt t = *this;
- uint8_t tmp = 1;
- BigInt a;
- a.import(&tmp, 1);
- this->operator+=(a);
+ *this += 1;
return t;
}
@@ -152,9 +145,7 @@
if(b >= a)
{
- uint8_t tmp = 0;
- result.import(&tmp, 1);
- return result;
+ return result = 0;
}
else
{
@@ -215,44 +206,30 @@
BigInt& BigInt::operator--()
{
- uint8_t tmp = 1;
- BigInt a;
- a.import(&tmp, 1);
-
- return (*this -= a);
+ return (*this -= 1);
}
BigInt BigInt::operator--(int)
{
BigInt t = *this;
- uint8_t tmp = 1;
- BigInt a;
- a.import(&tmp, 1);
- this->operator-=(a);
+ *this -= 1;
return t;
}
-/*
+
BigInt operator*(const BigInt &a, const BigInt& b)
{
BigInt result;
// if a == 0 or b == 0 then result = 0
if(!a || !b)
- {
- uint8_t tmp = 0;
- result.import(&tmp, 1);
- return result;
- }
+ return result = 0;
- uint8_t tmp = 1;
- BigInt one;
- one.import(&tmp, 1);
// if a == 1, then result = b
- if(a == one)
+ if(a == 1)
return (result = b);
// if b == 1, then result = a
- if(b == one)
+ if(b == 1)
return (result = a);
@@ -265,18 +242,13 @@
return (*this = (*this) * b);
}
-*/
BigInt operator>>(const BigInt &a, const uint32_t m)
{
BigInt result;
if(m == 0)
return result = a;
if(m/8 >= a.size)
- {
- uint8_t tmp = 0;
- result.import(&tmp, 0);
- return result;
- }
+ return result = 0;
result.size = a.size - m/8;
result.bits = new uint32_t[num(result.size)];