@@ -20,32 +20,32 @@ class BigInt : public Object {
20
20
public:
21
21
BigInt ()
22
22
: Object { ObjectType::BigInt } {
23
- bigint_init (data );
23
+ bigint_init (m_data );
24
24
}
25
25
26
26
BigInt (int b)
27
27
: Object { ObjectType::BigInt } {
28
- bigint_init (data );
29
- bigint_from_int (data , b);
28
+ bigint_init (m_data );
29
+ bigint_from_int (m_data , b);
30
30
}
31
31
32
32
template <typename T>
33
33
explicit BigInt (T b)
34
34
: Object { ObjectType::BigInt } {
35
- bigint_init (data );
35
+ bigint_init (m_data );
36
36
typename std::make_unsigned<T>::type x;
37
37
if constexpr (std::is_signed_v<T>) {
38
38
x = std::abs (b);
39
39
} else {
40
40
x = b;
41
41
}
42
42
int n = std::max ((long unsigned )1 , sizeof (x) / sizeof (bigint_word));
43
- bigint_reserve (data , n);
44
- bigint_raw_zero (data ->words , 0 , n);
45
- memcpy (data ->words , &x, sizeof (x));
46
- data ->size = bigint_raw_truncate (data ->words , n);
43
+ bigint_reserve (m_data , n);
44
+ bigint_raw_zero (m_data ->words , 0 , n);
45
+ memcpy (m_data ->words , &x, sizeof (x));
46
+ m_data ->size = bigint_raw_truncate (m_data ->words , n);
47
47
if constexpr (std::is_signed_v<T>) {
48
- bigint_set_neg (data , b < 0 );
48
+ bigint_set_neg (m_data , b < 0 );
49
49
}
50
50
}
51
51
@@ -54,68 +54,68 @@ class BigInt : public Object {
54
54
int len = snprintf (nullptr , 0 , " %.0f" , b);
55
55
char buf[len + 1 ];
56
56
snprintf (buf, len + 1 , " %.0f" , b);
57
- bigint_init (data );
58
- bigint_from_str_base (data , buf, 10 );
57
+ bigint_init (m_data );
58
+ bigint_from_str_base (m_data , buf, 10 );
59
59
}
60
60
61
61
BigInt (const char *s, int base = 10 )
62
62
: Object { ObjectType::BigInt } {
63
- bigint_init (data );
64
- bigint_from_str_base (data , s, base);
63
+ bigint_init (m_data );
64
+ bigint_from_str_base (m_data , s, base);
65
65
}
66
66
67
67
BigInt (const TM::String &s, int base = 10 )
68
68
: Object { ObjectType::BigInt } {
69
- bigint_init (data );
70
- bigint_from_str_base (data , s.c_str (), base);
69
+ bigint_init (m_data );
70
+ bigint_from_str_base (m_data , s.c_str (), base);
71
71
}
72
72
73
73
BigInt (const BigInt &b)
74
74
: Object { ObjectType::BigInt } {
75
- bigint_init (data );
76
- bigint_cpy (data , b.data );
75
+ bigint_init (m_data );
76
+ bigint_cpy (m_data , b.m_data );
77
77
}
78
78
79
79
BigInt &operator =(const BigInt &b) {
80
- bigint_cpy (data , b.data );
80
+ bigint_cpy (m_data , b.m_data );
81
81
return *this ;
82
82
}
83
83
84
84
~BigInt () {
85
- bigint_free (data );
85
+ bigint_free (m_data );
86
86
}
87
87
88
88
BigInt c_div (const BigInt &b) const {
89
89
BigInt c;
90
- bigint_div (c.data , data , b.data );
90
+ bigint_div (c.m_data , m_data , b.m_data );
91
91
return c;
92
92
}
93
93
94
94
BigInt c_mod (const BigInt &b) const {
95
95
BigInt c;
96
- bigint_mod (c.data , data , b.data );
96
+ bigint_mod (c.m_data , m_data , b.m_data );
97
97
return c;
98
98
}
99
99
100
100
static void div_mod (
101
101
BigInt "ient, BigInt &remainder,
102
102
const BigInt &biginterator,
103
103
const BigInt &denominator) {
104
- bigint_div_mod (quotient.data , remainder.data ,
105
- biginterator.data , denominator.data );
104
+ bigint_div_mod (quotient.m_data , remainder.m_data ,
105
+ biginterator.m_data , denominator.m_data );
106
106
}
107
107
108
108
void write (
109
109
char *dst,
110
110
int *n_dst,
111
111
int dst_base = 10 ,
112
112
int zero_terminate = 1 ) const {
113
- bigint_write_base (dst, n_dst, data , dst_base, zero_terminate);
113
+ bigint_write_base (dst, n_dst, m_data , dst_base, zero_terminate);
114
114
}
115
115
116
116
template <class STREAM >
117
117
STREAM &write (STREAM &s, int dst_base = 10 ) const {
118
- int n = bigint_write_size (data , dst_base);
118
+ int n = bigint_write_size (m_data , dst_base);
119
119
char *buf = (char *)malloc (n);
120
120
write (buf, &n, dst_base);
121
121
s << buf;
@@ -124,24 +124,24 @@ class BigInt : public Object {
124
124
}
125
125
126
126
BigInt &operator <<=(unsigned long long shift) {
127
- bigint_shift_left (data, data , shift);
127
+ bigint_shift_left (m_data, m_data , shift);
128
128
return *this ;
129
129
}
130
130
131
131
BigInt &operator >>=(unsigned long long shift);
132
132
133
133
BigInt &operator +=(const BigInt &b) {
134
- bigint_add (data, data , b.data );
134
+ bigint_add (m_data, m_data , b.m_data );
135
135
return *this ;
136
136
}
137
137
138
138
BigInt &operator -=(const BigInt &b) {
139
- bigint_sub (data, data , b.data );
139
+ bigint_sub (m_data, m_data , b.m_data );
140
140
return *this ;
141
141
}
142
142
143
143
BigInt &operator *=(const BigInt &b) {
144
- bigint_mul (data, data , b.data );
144
+ bigint_mul (m_data, m_data , b.m_data );
145
145
return *this ;
146
146
}
147
147
@@ -150,49 +150,49 @@ class BigInt : public Object {
150
150
BigInt &operator %=(const BigInt &b);
151
151
152
152
BigInt &operator ++() {
153
- bigint_add_word (data, data , 1 );
153
+ bigint_add_word (m_data, m_data , 1 );
154
154
return *this ;
155
155
}
156
156
157
157
BigInt &operator --() {
158
- bigint_sub_word (data, data , 1 );
158
+ bigint_sub_word (m_data, m_data , 1 );
159
159
return *this ;
160
160
}
161
161
162
162
BigInt &operator &=(const BigInt &b) {
163
- bigint_bitwise_and (data, data , b.data );
163
+ bigint_bitwise_and (m_data, m_data , b.m_data );
164
164
return *this ;
165
165
}
166
166
167
167
BigInt &operator |=(const BigInt &b) {
168
- bigint_bitwise_or (data, data , b.data );
168
+ bigint_bitwise_or (m_data, m_data , b.m_data );
169
169
return *this ;
170
170
}
171
171
172
172
BigInt &operator ^=(const BigInt &b) {
173
- bigint_bitwise_xor (data, data , b.data );
173
+ bigint_bitwise_xor (m_data, m_data , b.m_data );
174
174
return *this ;
175
175
}
176
176
177
177
BigInt operator -() {
178
178
BigInt b (*this );
179
- b.data ->neg = !b.data ->neg ;
179
+ b.m_data ->neg = !b.m_data ->neg ;
180
180
return b;
181
181
}
182
182
183
- bool operator ==(const BigInt &b) const { return bigint_cmp (data , b.data ) == 0 ; }
184
- bool operator !=(const BigInt &b) const { return bigint_cmp (data , b.data ) != 0 ; }
185
- bool operator <=(const BigInt &b) const { return bigint_cmp (data , b.data ) <= 0 ; }
186
- bool operator >=(const BigInt &b) const { return bigint_cmp (data , b.data ) >= 0 ; }
187
- bool operator <(const BigInt &b) const { return bigint_cmp (data , b.data ) < 0 ; }
188
- bool operator >(const BigInt &b) const { return bigint_cmp (data , b.data ) > 0 ; }
183
+ bool operator ==(const BigInt &b) const { return bigint_cmp (m_data , b.m_data ) == 0 ; }
184
+ bool operator !=(const BigInt &b) const { return bigint_cmp (m_data , b.m_data ) != 0 ; }
185
+ bool operator <=(const BigInt &b) const { return bigint_cmp (m_data , b.m_data ) <= 0 ; }
186
+ bool operator >=(const BigInt &b) const { return bigint_cmp (m_data , b.m_data ) >= 0 ; }
187
+ bool operator <(const BigInt &b) const { return bigint_cmp (m_data , b.m_data ) < 0 ; }
188
+ bool operator >(const BigInt &b) const { return bigint_cmp (m_data , b.m_data ) > 0 ; }
189
189
190
- bool operator ==(long long b) const { return bigint_cmp (data , BigInt (b).data ) == 0 ; }
191
- bool operator !=(long long b) const { return bigint_cmp (data , BigInt (b).data ) != 0 ; }
192
- bool operator <=(long long b) const { return bigint_cmp (data , BigInt (b).data ) <= 0 ; }
193
- bool operator >=(long long b) const { return bigint_cmp (data , BigInt (b).data ) >= 0 ; }
194
- bool operator <(long long b) const { return bigint_cmp (data , BigInt (b).data ) < 0 ; }
195
- bool operator >(long long b) const { return bigint_cmp (data , BigInt (b).data ) > 0 ; }
190
+ bool operator ==(long long b) const { return bigint_cmp (m_data , BigInt (b).m_data ) == 0 ; }
191
+ bool operator !=(long long b) const { return bigint_cmp (m_data , BigInt (b).m_data ) != 0 ; }
192
+ bool operator <=(long long b) const { return bigint_cmp (m_data , BigInt (b).m_data ) <= 0 ; }
193
+ bool operator >=(long long b) const { return bigint_cmp (m_data , BigInt (b).m_data ) >= 0 ; }
194
+ bool operator <(long long b) const { return bigint_cmp (m_data , BigInt (b).m_data ) < 0 ; }
195
+ bool operator >(long long b) const { return bigint_cmp (m_data , BigInt (b).m_data ) > 0 ; }
196
196
197
197
bool operator ==(const double &b) const {
198
198
if (isinf (b)) return false ;
@@ -224,78 +224,78 @@ class BigInt : public Object {
224
224
BigInt operator ^(const BigInt &b) const { return BigInt (*this ) ^= b; }
225
225
226
226
BigInt &set_bit (int bit_index) {
227
- bigint_set_bit (data , bit_index);
227
+ bigint_set_bit (m_data , bit_index);
228
228
return *this ;
229
229
}
230
230
231
231
BigInt &clr_bit (int bit_index) {
232
- bigint_clr_bit (data , bit_index);
232
+ bigint_clr_bit (m_data , bit_index);
233
233
return *this ;
234
234
}
235
235
236
236
bigint_word get_bit (int bit_index) const {
237
- return bigint_get_bit (data , bit_index);
237
+ return bigint_get_bit (m_data , bit_index);
238
238
}
239
239
240
240
int bitlength () const {
241
- return bigint_bitlength (data );
241
+ return bigint_bitlength (m_data );
242
242
}
243
243
244
244
int count_trailing_zeros () const {
245
- return bigint_count_trailing_zeros (data );
245
+ return bigint_count_trailing_zeros (m_data );
246
246
}
247
247
248
248
BigInt sqrt () const {
249
249
BigInt b;
250
- bigint_sqrt (b.data , data );
250
+ bigint_sqrt (b.m_data , m_data );
251
251
return b;
252
252
}
253
253
254
254
BigInt pow (bigint_word exponent) {
255
255
BigInt b;
256
- bigint_pow_word (b.data , data , exponent);
256
+ bigint_pow_word (b.m_data , m_data , exponent);
257
257
return b;
258
258
}
259
259
260
260
long to_long () const {
261
261
char buf[32 ];
262
- bigint_write (buf, 32 , data );
262
+ bigint_write (buf, 32 , m_data );
263
263
return strtol (buf, nullptr , 10 );
264
264
}
265
265
266
266
long long to_long_long () const {
267
267
char buf[32 ];
268
- bigint_write (buf, 32 , data );
268
+ bigint_write (buf, 32 , m_data );
269
269
return strtoll (buf, nullptr , 10 );
270
270
}
271
271
272
- inline bool is_negative () const { return data ->neg == 1 ; }
272
+ inline bool is_negative () const { return m_data ->neg == 1 ; }
273
273
274
274
double to_double () const ;
275
275
TM::String to_string (int base = 10 ) const ;
276
276
TM::String to_binary () const ;
277
277
278
278
static BigInt gcd (const BigInt &a, const BigInt &b) {
279
279
BigInt c;
280
- bigint_gcd (c.data , a.data , b.data );
280
+ bigint_gcd (c.m_data , a.m_data , b.m_data );
281
281
return c;
282
282
}
283
283
284
284
static BigInt rand_bits (int n_bits, bigint_rand_func rand_func) {
285
285
BigInt b;
286
- bigint_rand_bits (b.data , n_bits, rand_func);
286
+ bigint_rand_bits (b.m_data , n_bits, rand_func);
287
287
return b;
288
288
}
289
289
290
290
static BigInt rand_inclusive (const BigInt &n, bigint_rand_func rand_func) {
291
291
BigInt b;
292
- bigint_rand_inclusive (b.data , n.data , rand_func);
292
+ bigint_rand_inclusive (b.m_data , n.m_data , rand_func);
293
293
return b;
294
294
}
295
295
296
296
static BigInt rand_exclusive (const BigInt &n, bigint_rand_func rand_func) {
297
297
BigInt b;
298
- bigint_rand_exclusive (b.data , n.data , rand_func);
298
+ bigint_rand_exclusive (b.m_data , n.m_data , rand_func);
299
299
return b;
300
300
}
301
301
@@ -304,7 +304,7 @@ class BigInt : public Object {
304
304
}
305
305
306
306
private:
307
- bigint data [1 ];
307
+ bigint m_data [1 ];
308
308
};
309
309
310
310
}
0 commit comments