File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,8 +97,6 @@ int HugeInt::get_digit(int index) const {
9797 return number[index];
9898}
9999
100-
101-
102100int HugeInt::compare (HugeInt &b) const {
103101 if (negative && !b.negative ) {
104102 return -1 ;
@@ -137,6 +135,30 @@ int HugeInt::compare(HugeInt &b) const {
137135 }
138136}
139137
138+ bool operator ==(HugeInt &n1, HugeInt &n2) {
139+ return (n1.compare (n2) == 0 );
140+ }
141+
142+ bool operator !=(HugeInt &n1, HugeInt &n2) {
143+ return (n1.compare (n2) != 0 );
144+ }
145+
146+ bool operator >(HugeInt &n1, HugeInt &n2) {
147+ return (n1.compare (n2) == 1 );
148+ }
149+
150+ bool operator <=(HugeInt &n1, HugeInt &n2) {
151+ return (n1 < n2 || n1 == n2);
152+ }
153+
154+ bool operator <(HugeInt &n1, HugeInt &n2) {
155+ return (n1.compare (n2) == -1 );
156+ }
157+
158+ bool operator >=(HugeInt &n1, HugeInt &n2) {
159+ return (n1 > n2 || n1 == n2);
160+ }
161+
140162HugeInt HugeInt::simple_sum (HugeInt &b) {
141163 int max = 0 ;
142164 if (depth > b.depth ) {
Original file line number Diff line number Diff line change @@ -27,6 +27,15 @@ class HugeInt {
2727 void set_digit (int index, int digit); // set для разряда числа
2828 int get_digit (int index) const ; // get для разряда числа
2929
30+ friend bool operator == (HugeInt &n1, HugeInt &n2);
31+ friend bool operator != (HugeInt &n1, HugeInt &n2);
32+
33+ friend bool operator > (HugeInt &d1, HugeInt &d2);
34+ friend bool operator <= (HugeInt &d1, HugeInt &d2);
35+
36+ friend bool operator < (HugeInt &d1, HugeInt &d2);
37+ friend bool operator >= (HugeInt &d1, HugeInt &d2);
38+
3039 bool check_zero () const ;
3140 int compare (HugeInt &b) const ;
3241 HugeInt simple_sum (HugeInt &b);
@@ -37,7 +46,8 @@ class HugeInt {
3746 // операторы
3847 HugeInt operator -() const ;
3948
40- void shrink_to_fit ();
49+ void shrink_to_fit (); // обрезаем ненужные нули
50+
4151 void print_full (); // print для теста
4252 void print (); // print для теста
4353};
Original file line number Diff line number Diff line change 1313// * урезать размер числа, чтобы не было нулей
1414// ? ДОП:
1515// перегрузка операторов
16+ // * - операторы сравнения
17+ // - математические операторы
1618// умножение
1719// нахождение остатка от деления
1820
@@ -43,11 +45,11 @@ int main() {
4345 cout << b.get () << " - not zero " << endl;
4446 }
4547
46- if (a. compare (b) == 1 ) {
48+ if (a > b ) {
4749 cout << a.get () << " > " << b.get () << endl;
48- } else if (a. compare (b) == - 1 ) {
50+ } else if (a < b ) {
4951 cout << a.get () << " < " << b.get () << endl;
50- } else if (a. compare (b) == 0 ) {
52+ } else if (a == b ) {
5153 cout << a.get () << " = " << b.get () << endl;
5254 }
5355
You can’t perform that action at this time.
0 commit comments