Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

mpn.h

Go to the documentation of this file.
00001 
00003 /* Part of the C++ Multi-Precision arithmetic library
00004 
00005    Written by Brian Sipos <bjs5075@rit.edu> or <brian@sipos.yi.org>
00006    Copyright 2001,2002,2003 Brian Sipos
00007 
00008    The MP++ library is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012 
00013    The MP++ library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with the MP++ library; if not, write to the Free Software
00020    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef MPN_H
00024 #define MPN_H
00025 
00026 #include <string>
00027 #include "config.h"
00028 
00029 namespace mp {
00030 
00052 class mpn_ {
00053  public:
00054   typedef mp::size_type size_type;   
00055   typedef mp::limb_type limb_type;   
00056   typedef mp::limb_long_type limb_long_type; 
00057   typedef mp::radix_type radix_type; 
00058 
00059   static const size_type limb_size_bits; 
00060   static const limb_type limb_full; 
00061   static const size_type size_max;  
00062 
00064   static const std::string string_digits;
00065 
00067   static const byte capabilities();
00068 
00070   static void interrupt();
00071 
00073   mpn_(limb_type n = 0, size_type size = 0) :
00074     alloc_(0), data_(NULL) {
00075     init(n, size);
00076   }
00078   mpn_(const mpn_ &n, size_type size = 0) :
00079     alloc_(0), data_(NULL) {
00080     init(n, size);
00081   }
00082 
00084   ~mpn_() {
00085     delete [] data_;
00086   }
00087 
00095   void init(limb_type n, size_type size = 0);
00096 
00102   void init(const mpn_ &n, size_type size = 0);
00103 
00104   void clear(); 
00105 
00109   void resize(size_type size);
00110 
00115   void swap(mpn_ &n);
00117 
00122   size_type size() const;
00123 
00126   bool isZero() const;
00127 
00129   size_type low_zeros() const;
00131 
00138   void shift_l(size_type n);
00143   void shift_r(size_type n);
00145 
00153   void setString(const std::string &s, radix_type b);
00154 
00160   std::string getString(radix_type b) const;
00162 
00163   void print() const; 
00164 
00168   raw_type getRaw() const; 
00169   void setRaw(const raw_type &data); 
00170 
00171 
00179   const limb_type & operator [] (size_type i) const;
00183   limb_type & operator [] (size_type i);
00184 
00190   int compare(const mpn_ &n) const;
00192 
00197   void add(const mpn_ &n);
00198 
00201   void sub(const mpn_ &n);
00202 
00205   void mul(const mpn_ &n);
00206 
00210   void div_mod(mpn_ &n);
00212 
00215   void sqr(); 
00216 
00217 
00222   static void prng_seed(limb_long_type seed);
00223 
00226   static void prng_seed(const mpn_ &seed);
00227 
00230   void prng(size_type n);
00232 
00237   size_type popcount() const; // returns the number of set bits
00238 
00245   void bitwise(const mpn_ &y, int type);
00246 
00250   void bitwise_not();
00252 
00255   void setUse();
00256 
00257  protected:
00258   size_type alloc_; 
00259   size_type use_;   
00260   limb_type *data_; 
00261 
00262 #ifdef _MP_INTERRUPTABLE
00263   static bool interrupted; 
00264 
00268   void onInterrupt() const;
00269 #endif
00270 
00277   void add_l(limb_type n);
00278 
00282   void sub_l(limb_type n);
00283 
00286   void mul_l(limb_type n);
00287 
00291   void div_mod_l(limb_type &n);
00293 };
00294 
00300 radix_type guessbase(const std::string &s, radix_type b);
00301 
00307 std::string::size_type isNum(const std::string &s, radix_type b);
00308 
00315 void setchunk(mpn_::radix_type b, std::string::size_type &chunksize,
00316               mpn_::limb_type &chunk);
00317 
00326 void stringclean(std::string &s, mpn_::radix_type b, int clear_zero);
00327 
00329 } // End namespace mp++
00330 #endif

Generated on Fri Feb 4 16:17:55 2005 for LibMP++ by  doxygen 1.4.1