00001
00002
00003
00004
00005
00016
00017 #include<iostream.h>
00018 #include<stdlib.h>
00019 #include<string.h>
00020 #include<ctype.h>
00021 #include<strstrea.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;
00034 const digit max_digit = 0xFFFFFFFF;
00035 const int bits_per_digit = 32;
00036 # include"bigar32.h"
00037 # else
00038 typedef unsigned int digit;
00039 const digit max_digit = 0xFFFF;
00040 const int bits_per_digit = 16;
00041 # include"bigarbc.h"
00042 # endif
00043 #else
00044 typedef unsigned int digit;
00045 const digit max_digit = 0xFFFF;
00046 const int bits_per_digit = 16;
00047 # include"bigar.h"
00048 #endif
00049
00050
00054
00055 class big_int
00056 {
00057
00064
00065 public:
00066
00067 big_int();
00068 big_int(char *str);
00069 big_int(const big_int & b);
00070 big_int(int b);
00071 ~big_int();
00072
00073 big_int & operator = (const big_int & b);
00074
00076 size_t length();
00077
00078 int operator [] (size_t k);
00079
00080
00081
00082
00083
00084
00086
00088
00090
00091
00093
00099 friend int cmp(const big_int & a, const big_int & b);
00100
00102 friend int operator == (const big_int & a, const big_int & b);
00103
00105 friend int operator != (const big_int & a, const big_int & b);
00106
00108 friend int operator > (const big_int & a, const big_int & b);
00109
00111 friend int operator >= (const big_int & a, const big_int & b);
00112
00114 friend int operator < (const big_int & a, const big_int & b);
00115
00117 friend int operator <= (const big_int & a, const big_int & b);
00118
00119 friend big_int operator + (const big_int & a);
00120 friend big_int operator - (const big_int & a);
00121
00123 friend big_int operator + (const big_int & b, const big_int & c);
00125 friend big_int operator - (const big_int & b, const big_int & c);
00127 friend big_int operator *(const big_int & b, const big_int & c);
00129 friend big_int operator / (const big_int & b, const big_int & c);
00131 friend big_int operator % (const big_int & b, const big_int & c);
00133 friend big_int & operator += (big_int & b, const big_int & c);
00135 friend big_int & operator -= (big_int & b, const big_int & c);
00137 friend big_int & operator *= (big_int & b, const big_int & c);
00139 friend big_int & operator /= (big_int & b, const big_int & c);
00141 friend big_int & operator %= (big_int & b, const big_int & c);
00142
00144
00145 friend void divide(big_int & a, const big_int & b, const big_int & c,
00146 big_int & res);
00147
00149 friend big_int random_number(size_t length);
00150 friend big_int random_number1(size_t length);
00151
00152
00153 private:
00154
00155
00156
00157
00158 struct big_struct
00159 {
00160 int sign;
00161 digit *data;
00162 size_t len;
00163 int refs;
00164 } *number;
00165
00166
00167 void alloc_number(int new_sign, digit * new_mem, size_t new_len);
00168 void free_number();
00169 void free_mem_and_alloc_number(int new_sign, digit * new_data, size_t new_len);
00170 void alloc_zero();
00171 void free_mem_and_alloc_zero();
00172
00173 };
00174 #endif BIGARITH_H_