Main Page   Compound List   File List   Compound Members   File Members   Examples  

bigarith.h

Go to the documentation of this file.
00001 //  N.Yu.Zolotykh 1999, 2000
00002 //  University of Nizhni Novgorod, Russia
00003 //  Arageli 1.02
00004 
00005 
00016 
00017 #include<iostream.h>
00018 #include<stdlib.h>
00019 #include<string.h>
00020 #include<ctype.h>
00021 #include<strstream.h>
00022 #include "arageli.h"
00023 
00024 #ifndef __cplusplus
00025 #  error Must use C++ for the type big_int.
00026 #endif
00027 
00028 #ifndef BIGARITH_H_
00029 #define BIGARITH_H_
00030 
00031 #ifdef USE_ASM
00032 #  if defined(__WIN32__) || defined (__WATCOMC__)
00033      typedef unsigned int digit; // 4 bytes
00034      const digit max_digit = 0xFFFFFFFF;
00035 #    include"bigar32.h"
00036 #  else
00037      typedef unsigned int digit;
00038      const digit max_digit = 0xFFFF;
00039 #    include"bigarbc.h"
00040 #  endif
00041 #else
00042      typedef unsigned int digit;
00043      const digit max_digit = 0xFFFF;
00044 #    include"bigar.h"
00045 #endif
00046 
00047 
00051 
00052 class big_int
00053 {
00054 
00061 
00062  public:
00063 
00064   big_int();                    
00065   big_int(char *str);           
00066   big_int(const big_int & b);   
00067   big_int(int b);               
00068   ~big_int();                   
00069 
00070   big_int & operator = (const big_int & b);     
00071 
00073   // friend void string_to_num(char *s, big_int & b);
00074   // надо бы убрать вообще эту функцию,
00075   // а где-нибудь в powerest создать шаблон b=s
00076 
00078   // void to_string(char *string, size_t size, digit radix = 10) const;
00080   friend ostream & operator << (ostream & s, const big_int & x);
00082   friend istream & operator >> (istream & s, big_int & x);
00083 
00085 
00091   friend int cmp(const big_int & a, const big_int & b);
00092 
00094   friend int operator == (const big_int & a, const big_int & b);
00095 
00097   friend int operator != (const big_int & a, const big_int & b);
00098 
00100   friend int operator > (const big_int & a, const big_int & b);
00101 
00103   friend int operator >= (const big_int & a, const big_int & b);
00104 
00106   friend int operator < (const big_int & a, const big_int & b);
00107 
00109   friend int operator <= (const big_int & a, const big_int & b);
00110 
00111   friend big_int operator + (const big_int & a);       
00112   friend big_int operator - (const big_int & a);       
00113 
00115   friend big_int operator + (const big_int & b, const big_int & c);
00117   friend big_int operator - (const big_int & b, const big_int & c);
00119   friend big_int operator *(const big_int & b, const big_int & c);
00121   friend big_int operator / (const big_int & b, const big_int & c);
00123   friend big_int operator % (const big_int & b, const big_int & c);
00125   friend big_int & operator += (big_int & b, const big_int & c);
00127   friend big_int & operator -= (big_int & b, const big_int & c);
00129   friend big_int & operator *= (big_int & b, const big_int & c);
00131   friend big_int & operator /= (big_int & b, const big_int & c);
00133   friend big_int & operator %= (big_int & b, const big_int & c);
00134 
00136 
00137   friend void divide(big_int & a, const big_int & b, const big_int & c,
00138       big_int & res);
00139 
00141   friend big_int random_number(int length);
00142 
00143 
00144  private:
00145 
00146   // the following type is used inside the big_arith unit and implements
00147   // the storage for a Big Integer Number
00148 
00149   struct big_struct
00150   {
00151     int sign;                   // the sign: 0, 1 or -1
00152     digit *data;                // the storage for digits
00153     size_t len;                 // the number of digits
00154     int refs;                   // the number of points to this number
00155   } *number;
00156 
00157   // number allocation routines
00158   void alloc_number(int new_sign, digit * new_mem, size_t new_len);
00159   void free_number();
00160   void free_mem_and_alloc_number(int new_sign, digit * new_data, size_t new_len);
00161   void alloc_zero();
00162   void free_mem_and_alloc_zero();
00163 
00164 };
00165 #endif BIGARITH_H_

Generated at Mon Oct 8 09:03:50 2001 for Arageli by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001