Hey Darko, thank you very much for your reply! It's very much appreciated.
Yup, I agree with you the pleasure of finishing it is priceless~ I'm working for it in full time right now!
Well, this is my progress so far:
- Implemented Addition operator
- Implemented Subtraction operator
- Implemented negative sign / operation
The addition of negative sign is kinda tedious, as I have to consider each situation (which has total 4 possibilities) while adding / subtracting two BigIntegers. But nevertheless, I've just finished implemented it, and finished debugging / optimizing it. I'm quite satisfied with the speed, but I'm just a little bit frustrated about the code though. It's kinda messy, I think I gotta clean it up a bit
By the way, I've tried to experiment with the code a lot... Sometimes, I'll just change a line of code in a certain function, and time the speed (by looping and calling the function), and test if the change makes the code faster. Most of the changes met my expectations, but here's one situation that I do not expect.
I've tried to overload the assignment operator, and by looping this line (something like BigInt x = "123"; ) 10000000 times, i found that by implementing the assignment operator manually, it runs faster than without implementing it myself.
Here is the code for my overloading assignment operator
Code: Select all
const BigInt& BigInt::operator =(const BigInt &b)
{
this->numDigits = b.numDigits;
this->isNegative = b.isNegative;
for (int i = 0; i < numDigits; i++)
{
this->digits[i] = b.digits[i];
}
return *this;
}
Can someone explains this? I thought the default assignment operator does the exact same thing? In fact, I expected it will run about the same (or even faster) than my overloaded assignment operator...
