Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 {
  int length;
  vector <short int> number;
  LargeNumber clone(){            
        return (*this);
  int Length() const;
  vector <short int> Number()const;      
  static LargeNumber& GenerateOne(int);// create new LargeNumber
  static void Print(const LargeNumber& print);
  LargeNumber(const LargeNumber& obj);
  explicit LargeNumber(int len);      
  explicit LargeNumber(vector <short int>);
  void Kill();
  LargeNumber& operator= (const LargeNumber& );
  LargeNumber& operator--();    
  LargeNumber& operator++();
  bool operator<(const LargeNumber&)const;


 class Field {
  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&);
         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& );

share|improve this question
My first reaction: don't use abbreviated and cryptic names such as C_C and Z_p, nor method names like Mul and Sum. Code is written once, read many times. Even with experimental or throwaway code, it is best to get into the habit of using meaningful, easy to read names always. Your future teammates - and the future you - will be glad you did. – Péter Török Feb 12 '12 at 17:25
@PéterTörök have a look at the mathematical term 'Field', which is (loosely speaking) a Group on which both addition and multiplication and their inverses (subtraction, division) are defined. E.g Q (ratios), R (real numbers), and C (complex numbers) are fields with infinite number of elements, though the integers are not. The only fields with a finite number of elements, are based on the integers (Z) modulo a prime p (and multi-dimensional vectors of the same Z_p). Therefor Z_p and C_C are perfectly understandable in this domain, and are not cryptic. – Sjoerd Feb 12 '12 at 22:44
ok, thank you! will rewrite code! fft - fast fourier transformation. Multiplication of Big numbers can be done with using fft (Schönhage–Strassen algorithm) and more about fft: this operation is determine on group (and also on field and ring too). so, really Field must be named like FftCore or something similar. and C_C - ComplexField and Z_P Modulo_Prime_P or something similar. – gaussblurinc Feb 13 '12 at 6:29
but about another task: i need to gather statistics about time it executes and about count of operations it takes. also i need to make logs of everyting. for this i suppose about classes Statistics, TimeKeeper ( maybe a part of Statistics) and LogFormer But can't understand HOW they must interact with previous classes. – gaussblurinc Feb 13 '12 at 6:29
@Sjoerd, thanks for the explanation. I wasn't aware of these terms (IIRC the Hungarian terminology we studied at uni was different). I removed my comment. – Péter Török Feb 13 '12 at 9:24
up vote 4 down vote accepted

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).

share|improve this answer
Wow, I should +1 you solely for understanding the question! :) – BenR Feb 12 '12 at 20:34
I guess the OP's task is to implement this by hand. – Péter Török Feb 12 '12 at 21:00
i need to check number for it prime-property, both two numbers and then must calculate it ( multiplication ) about realization - any working under Windows-Os ( also GUI - Qt the best way ) – gaussblurinc Feb 13 '12 at 18:01
If you're dealing with whole numbers, GMP will do it. It also includes an example primality tester. There are faster algorithms, but it's at least reasonably simple (I think it's Pollard's rho method). – James Youngman Mar 14 '12 at 1:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.