-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbig_integer.h
More file actions
executable file
·162 lines (84 loc) · 4.4 KB
/
big_integer.h
File metadata and controls
executable file
·162 lines (84 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#pragma once
//#include "OptimizedArrayList.h"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
struct big_integer {
big_integer();
big_integer(const big_integer &other) = default;
big_integer(int a);
big_integer(size_t a, bool);
explicit big_integer(std::string const &str);
~big_integer() = default;
big_integer(big_integer &&other) = default;
friend std::ostream &operator<<(std::ostream &, big_integer const &);
friend std::istream &operator>>(std::istream &, big_integer &);
[[nodiscard]] std::string to_string() const;
big_integer &operator/=(big_integer const &rhs);
big_integer &operator%=(big_integer const &rhs);
big_integer &operator&=(big_integer const &rhs);
big_integer &operator|=(big_integer const &rhs);
big_integer &operator^=(big_integer const &rhs);
big_integer &operator+=(const big_integer &);
big_integer &operator*=(const big_integer &);
big_integer &operator-=(const big_integer &);
big_integer &operator<<=(short shift);
big_integer &operator>>=(short shift);
friend bool operator==(big_integer const &a, big_integer const &b);
friend bool operator!=(big_integer const &a, big_integer const &b);
friend bool operator<(big_integer const &a, big_integer const &b);
friend bool operator>(big_integer const &a, big_integer const &b);
friend bool operator<=(big_integer const &a, big_integer const &b);
friend bool operator>=(big_integer const &a, big_integer const &b);
friend big_integer operator+(big_integer a, big_integer const &b);
friend big_integer operator-(big_integer a, big_integer const &b);
friend big_integer operator*(big_integer const &a, big_integer const &b);
friend big_integer operator/(big_integer const &a, big_integer const &b);
friend big_integer operator%(big_integer a, big_integer const &b);
friend big_integer operator&(big_integer a, big_integer const &b);
friend big_integer operator|(big_integer a, big_integer const &b);
friend big_integer operator^(big_integer a, big_integer const &b);
friend big_integer operator<<(big_integer a, int b);
friend big_integer operator>>(big_integer a, int b);
friend void swap(big_integer &a, big_integer &b) noexcept;
big_integer operator+() const;
big_integer operator-() const;
big_integer operator~();
big_integer &operator++();
big_integer &operator--();
big_integer &operator=(big_integer const &other) = default;
big_integer &operator=(big_integer &&other) = default;
private:
void cutBadZero();
big_integer reverseIt();
void mul_long_short(unsigned int number);
void add_long_short(unsigned int number);
friend std::string to_string(big_integer const &a);
bool compare_without_sign_and_equals(const big_integer &);
unsigned int div_long_short(unsigned int number);
[[nodiscard]] short compare(const big_integer &other) const;
friend void divide(big_integer &res, const big_integer &a, const big_integer &b);
friend void sub(big_integer &a, const big_integer &b);
std::vector<uint32_t> digits;
// OptimizedArrayList digits;
int8_t sign;
};
big_integer operator+(big_integer a, big_integer const &b);
big_integer operator-(big_integer a, big_integer const &b);
big_integer operator*(big_integer const &a, big_integer const &b);
big_integer operator/(big_integer const &a, big_integer const &b);
big_integer operator%(big_integer a, big_integer const &b);
big_integer operator&(big_integer a, big_integer const &b);
big_integer operator|(big_integer a, big_integer const &b);
big_integer operator^(big_integer a, big_integer const &b);
big_integer operator<<(big_integer a, int b);
big_integer operator>>(big_integer a, int b);
bool operator==(big_integer const &a, big_integer const &b);
bool operator!=(big_integer const &a, big_integer const &b);
bool operator<(big_integer const &a, big_integer const &b);
bool operator>(big_integer const &a, big_integer const &b);
bool operator<=(big_integer const &a, big_integer const &b);
bool operator>=(big_integer const &a, big_integer const &b);
void swap(big_integer &a, big_integer &b) noexcept;
void divide(big_integer &res, const big_integer &a, const big_integer &b);