Advertisement
thecplusplusguy

bignum library in C++ - bignum.h

Jul 6th, 2012
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. //a bignum library written in C++, it can (in theory) calculate with 4 billion digit long numbers
  2. //this is mostly for demonstration purposes, if you need performance, use something like GNU arbitrary precision library
  3. //Implemented by: http://www.youtube.com/user/thecplusplusguy
  4. //this might be an older version, I have to check
  5. #ifndef BIGNUM_H
  6. #define BIGNUM_H
  7. #include <iostream>
  8. #include <cmath>
  9. #include <cstring>
  10.  
  11. class bignum{
  12.     int* num;
  13.     int size;
  14.     bool minus;
  15.     void remainder();
  16.     public:
  17.     bignum();
  18.     bignum(int);
  19.     bignum(long);
  20.     bignum(const bignum& b);
  21.     bignum(const char* c);
  22.     bignum(std::string& c);
  23.     ~bignum();
  24.     int getSize() const;
  25.     int* getNum() const;
  26.     int getNumSize() const;
  27.     int numLength(int a);
  28.    
  29.     void allocate(int s);
  30.    
  31.     friend std::ostream& operator<<(std::ostream& os,const bignum& b);
  32.     friend bignum& operator++(const bignum& bn);
  33.     friend bignum& operator--(const bignum& bn);
  34.    
  35.     //compare
  36.    
  37.     bool operator==(const bignum& b) const;
  38.     bool operator==(int n) const;
  39.     bool operator==(const char* c) const;
  40.    
  41.     bool operator>(const bignum& b) const;
  42.     bool operator>(int n) const;
  43.     bool operator>(const char* c) const;   
  44.  
  45.     bool operator<(const bignum& b) const;
  46.     bool operator<(int n) const;
  47.     bool operator<(const char* c) const;   
  48.  
  49.     bool operator<=(const bignum& b) const;
  50.     bool operator<=(int n) const;
  51.     bool operator<=(const char* c) const;
  52.  
  53.     bool operator>=(const bignum& b) const;
  54.     bool operator>=(int n) const;
  55.     bool operator>=(const char* c) const;
  56.  
  57.     bool operator!=(const bignum& b) const;
  58.     bool operator!=(int n) const;
  59.     bool operator!=(const char* c) const;
  60.  
  61.  
  62.     //operations
  63.    
  64.     bignum& operator=(int num);
  65.     bignum& operator=(const char* c);
  66.     bignum& operator=(const bignum& b);
  67.    
  68.     bignum operator+(int num);
  69.     bignum operator+(const bignum& bn);
  70.     bignum operator+(const char* c);
  71.    
  72.     bignum operator-(int num);
  73.     bignum operator-(const bignum& bn);
  74.     bignum operator-(const char* c);
  75.  
  76.  
  77.     bignum operator*(int num);
  78.     bignum operator*(const bignum& bn);
  79.     bignum operator*(const char* c);
  80.  
  81.  
  82.     bignum operator/(int num);
  83.     bignum operator/(const bignum& bn);
  84.     bignum operator/(const char* c);
  85.    
  86.     bignum operator%(int num);
  87.     bignum operator%(const bignum& bn);
  88.     bignum operator%(const char* c);
  89.  
  90.     bignum& operator/=(int num);
  91.     bignum& operator/=(const bignum& bn);
  92.     bignum& operator/=(const char* c);
  93.  
  94.    
  95.     bignum& operator+=(int num);
  96.     bignum& operator+=(const bignum& bn);
  97.     bignum& operator+=(const char* c);
  98.    
  99.     bignum& operator-=(int num);
  100.     bignum& operator-=(const bignum& bn);
  101.     bignum& operator-=(const char* c);
  102.    
  103.     bignum& operator*=(int num);
  104.     bignum& operator*=(const bignum& bn);
  105.     bignum& operator*=(const char* c);
  106.    
  107.     bignum& operator%=(int num);
  108.     bignum& operator%=(const bignum& bn);
  109.     bignum& operator%=(const char* c);
  110.  
  111.     bignum& operator++();
  112.     bignum& operator--();
  113. };
  114. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement