Trying to design small project in right way and have a trouble in it:\\ about ta
ID: 652457 • Letter: T
Question
Trying to design small project in right way and have a trouble in it:
about task: need to realize multiplication of big numbers, using fft
First, i have classes
class LargeNumber{};
class Field{}; -- abstract (maybe interface would be better)
class C_C:public virtual Field{};
class Z_p:public virtual Field{};
So, LargeNumber can use Z_P(modulo P) or C_C(complex) classes (more correct: C_C and Z_P have Mul and Sum functions to multiply LargeNumber objects)
but another task more interesting and difficult.
I need to calculate all operations and time each 'big' operation take. And also need to throw messages and create logs.
How to solve this problem? ( what should i do? )
Also will be great, if you comment patterns and your best practices. and so this classes:
class LargeNumber {
private:
int length;
vector <short int> number;
public:
//prototype
LargeNumber clone(){
return (*this);
}
//get
int Length() const;
vector <short int> Number()const;
//static
static LargeNumber& GenerateOne(int);// create new LargeNumber
static void Print(const LargeNumber& print);
//constructors
LargeNumber();
LargeNumber(const LargeNumber& obj);
explicit LargeNumber(int len);
explicit LargeNumber(vector <short int>);
LargeNumber(int,int);
//destructors
~LargeNumber();
void Kill();
//operators
LargeNumber& operator= (const LargeNumber& );
LargeNumber& operator--();
LargeNumber& operator++();
bool operator<(const LargeNumber&)const;
};
class Field {
private:
inline int max(const int a, const int b){return (a>b?a:b);}
inline int min(const int a, const int b){return (a<b?a:b);}
int i;
//need Mod and 2**P-1
LargeNumber& Deux (const int );
LargeNumber& Mod (LargeNumber&);
public:
virtual ~Field();
virtual LargeNumber& Sum (const LargeNumber& , const LargeNumber& );
virtual LargeNumber& Sub (const LargeNumber& , const LargeNumber& );
virtual LargeNumber& Mul (const LargeNumber& , const LargeNumber& );
virtual LargeNumber& Pow (const LargeNumber& , const LargeNumber& );
virtual bool Prime (LargeNumber& );
};
Explanation / Answer
Don't reinvent the wheel, use a good existing implementation of arbitrary-precision arithmetic, like Bruno Haible's CLN (which is partly based on GNU GMP).