Designing my own Big Integer class, need your suggestions :)
Posted: Tue Jul 25, 2006 9:27 pm
Hey guys and gals, I'm getting excited to code my own Big Integer library. But of course, I will need your advices and suggestions in making it as efficient as possible! I designed this Big Integer class with some references to the BigInteger class designed by Suman, which can be downloaded here.
I used a fixed array to store each individual digit of a Big Integer, an integer to store the number of digits in the Big Integer, and a boolean value if the Big Integer is negative.
Ok, here is the code for the abs() function in my library (which returns the absolute value of the Big Integer).
I'm wondering if there's any way of making the abs() function as efficient as possible? (Maybe returning by reference? But I don't really know how) By the way, I want it to pass by value because I don't want to change the original Big Integer.
What I saw from Suman's class is
I do not understand this..
"BigInteger& ret = *new BigInteger(arg);"
Can anyone please explain?
And, thanks for reading this post and helping!
I used a fixed array to store each individual digit of a Big Integer, an integer to store the number of digits in the Big Integer, and a boolean value if the Big Integer is negative.
Ok, here is the code for the abs() function in my library (which returns the absolute value of the Big Integer).
Code: Select all
BigInt abs(BigInt a)
{
a.isNegative = false;
return a;
}
What I saw from Suman's class is
Code: Select all
BigInteger& abs(BigInteger& arg)
{
BigInteger& ret = *new BigInteger(arg);
ret.isNegative = false;
return ret;
}
"BigInteger& ret = *new BigInteger(arg);"
Can anyone please explain?
And, thanks for reading this post and helping!
