00001
00002
00003
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;
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
00074
00075
00076
00078
00080
00082
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
00147
00148
00149 struct big_struct
00150 {
00151 int sign;
00152 digit *data;
00153 size_t len;
00154 int refs;
00155 } *number;
00156
00157
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_