Skip to content

Commit 268bdea

Browse files
committed
Prefix private BigInt member name
1 parent 1982edc commit 268bdea

File tree

2 files changed

+80
-80
lines changed

2 files changed

+80
-80
lines changed

include/natalie/bigint.hpp

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ class BigInt : public Object {
2020
public:
2121
BigInt()
2222
: Object { ObjectType::BigInt } {
23-
bigint_init(data);
23+
bigint_init(m_data);
2424
}
2525

2626
BigInt(int b)
2727
: 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);
3030
}
3131

3232
template <typename T>
3333
explicit BigInt(T b)
3434
: Object { ObjectType::BigInt } {
35-
bigint_init(data);
35+
bigint_init(m_data);
3636
typename std::make_unsigned<T>::type x;
3737
if constexpr (std::is_signed_v<T>) {
3838
x = std::abs(b);
3939
} else {
4040
x = b;
4141
}
4242
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);
4747
if constexpr (std::is_signed_v<T>) {
48-
bigint_set_neg(data, b < 0);
48+
bigint_set_neg(m_data, b < 0);
4949
}
5050
}
5151

@@ -54,68 +54,68 @@ class BigInt : public Object {
5454
int len = snprintf(nullptr, 0, "%.0f", b);
5555
char buf[len + 1];
5656
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);
5959
}
6060

6161
BigInt(const char *s, int base = 10)
6262
: 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);
6565
}
6666

6767
BigInt(const TM::String &s, int base = 10)
6868
: 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);
7171
}
7272

7373
BigInt(const BigInt &b)
7474
: 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);
7777
}
7878

7979
BigInt &operator=(const BigInt &b) {
80-
bigint_cpy(data, b.data);
80+
bigint_cpy(m_data, b.m_data);
8181
return *this;
8282
}
8383

8484
~BigInt() {
85-
bigint_free(data);
85+
bigint_free(m_data);
8686
}
8787

8888
BigInt c_div(const BigInt &b) const {
8989
BigInt c;
90-
bigint_div(c.data, data, b.data);
90+
bigint_div(c.m_data, m_data, b.m_data);
9191
return c;
9292
}
9393

9494
BigInt c_mod(const BigInt &b) const {
9595
BigInt c;
96-
bigint_mod(c.data, data, b.data);
96+
bigint_mod(c.m_data, m_data, b.m_data);
9797
return c;
9898
}
9999

100100
static void div_mod(
101101
BigInt &quotient, BigInt &remainder,
102102
const BigInt &biginterator,
103103
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);
106106
}
107107

108108
void write(
109109
char *dst,
110110
int *n_dst,
111111
int dst_base = 10,
112112
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);
114114
}
115115

116116
template <class STREAM>
117117
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);
119119
char *buf = (char *)malloc(n);
120120
write(buf, &n, dst_base);
121121
s << buf;
@@ -124,24 +124,24 @@ class BigInt : public Object {
124124
}
125125

126126
BigInt &operator<<=(unsigned long long shift) {
127-
bigint_shift_left(data, data, shift);
127+
bigint_shift_left(m_data, m_data, shift);
128128
return *this;
129129
}
130130

131131
BigInt &operator>>=(unsigned long long shift);
132132

133133
BigInt &operator+=(const BigInt &b) {
134-
bigint_add(data, data, b.data);
134+
bigint_add(m_data, m_data, b.m_data);
135135
return *this;
136136
}
137137

138138
BigInt &operator-=(const BigInt &b) {
139-
bigint_sub(data, data, b.data);
139+
bigint_sub(m_data, m_data, b.m_data);
140140
return *this;
141141
}
142142

143143
BigInt &operator*=(const BigInt &b) {
144-
bigint_mul(data, data, b.data);
144+
bigint_mul(m_data, m_data, b.m_data);
145145
return *this;
146146
}
147147

@@ -150,49 +150,49 @@ class BigInt : public Object {
150150
BigInt &operator%=(const BigInt &b);
151151

152152
BigInt &operator++() {
153-
bigint_add_word(data, data, 1);
153+
bigint_add_word(m_data, m_data, 1);
154154
return *this;
155155
}
156156

157157
BigInt &operator--() {
158-
bigint_sub_word(data, data, 1);
158+
bigint_sub_word(m_data, m_data, 1);
159159
return *this;
160160
}
161161

162162
BigInt &operator&=(const BigInt &b) {
163-
bigint_bitwise_and(data, data, b.data);
163+
bigint_bitwise_and(m_data, m_data, b.m_data);
164164
return *this;
165165
}
166166

167167
BigInt &operator|=(const BigInt &b) {
168-
bigint_bitwise_or(data, data, b.data);
168+
bigint_bitwise_or(m_data, m_data, b.m_data);
169169
return *this;
170170
}
171171

172172
BigInt &operator^=(const BigInt &b) {
173-
bigint_bitwise_xor(data, data, b.data);
173+
bigint_bitwise_xor(m_data, m_data, b.m_data);
174174
return *this;
175175
}
176176

177177
BigInt operator-() {
178178
BigInt b(*this);
179-
b.data->neg = !b.data->neg;
179+
b.m_data->neg = !b.m_data->neg;
180180
return b;
181181
}
182182

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; }
189189

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; }
196196

197197
bool operator==(const double &b) const {
198198
if (isinf(b)) return false;
@@ -224,78 +224,78 @@ class BigInt : public Object {
224224
BigInt operator^(const BigInt &b) const { return BigInt(*this) ^= b; }
225225

226226
BigInt &set_bit(int bit_index) {
227-
bigint_set_bit(data, bit_index);
227+
bigint_set_bit(m_data, bit_index);
228228
return *this;
229229
}
230230

231231
BigInt &clr_bit(int bit_index) {
232-
bigint_clr_bit(data, bit_index);
232+
bigint_clr_bit(m_data, bit_index);
233233
return *this;
234234
}
235235

236236
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);
238238
}
239239

240240
int bitlength() const {
241-
return bigint_bitlength(data);
241+
return bigint_bitlength(m_data);
242242
}
243243

244244
int count_trailing_zeros() const {
245-
return bigint_count_trailing_zeros(data);
245+
return bigint_count_trailing_zeros(m_data);
246246
}
247247

248248
BigInt sqrt() const {
249249
BigInt b;
250-
bigint_sqrt(b.data, data);
250+
bigint_sqrt(b.m_data, m_data);
251251
return b;
252252
}
253253

254254
BigInt pow(bigint_word exponent) {
255255
BigInt b;
256-
bigint_pow_word(b.data, data, exponent);
256+
bigint_pow_word(b.m_data, m_data, exponent);
257257
return b;
258258
}
259259

260260
long to_long() const {
261261
char buf[32];
262-
bigint_write(buf, 32, data);
262+
bigint_write(buf, 32, m_data);
263263
return strtol(buf, nullptr, 10);
264264
}
265265

266266
long long to_long_long() const {
267267
char buf[32];
268-
bigint_write(buf, 32, data);
268+
bigint_write(buf, 32, m_data);
269269
return strtoll(buf, nullptr, 10);
270270
}
271271

272-
inline bool is_negative() const { return data->neg == 1; }
272+
inline bool is_negative() const { return m_data->neg == 1; }
273273

274274
double to_double() const;
275275
TM::String to_string(int base = 10) const;
276276
TM::String to_binary() const;
277277

278278
static BigInt gcd(const BigInt &a, const BigInt &b) {
279279
BigInt c;
280-
bigint_gcd(c.data, a.data, b.data);
280+
bigint_gcd(c.m_data, a.m_data, b.m_data);
281281
return c;
282282
}
283283

284284
static BigInt rand_bits(int n_bits, bigint_rand_func rand_func) {
285285
BigInt b;
286-
bigint_rand_bits(b.data, n_bits, rand_func);
286+
bigint_rand_bits(b.m_data, n_bits, rand_func);
287287
return b;
288288
}
289289

290290
static BigInt rand_inclusive(const BigInt &n, bigint_rand_func rand_func) {
291291
BigInt b;
292-
bigint_rand_inclusive(b.data, n.data, rand_func);
292+
bigint_rand_inclusive(b.m_data, n.m_data, rand_func);
293293
return b;
294294
}
295295

296296
static BigInt rand_exclusive(const BigInt &n, bigint_rand_func rand_func) {
297297
BigInt b;
298-
bigint_rand_exclusive(b.data, n.data, rand_func);
298+
bigint_rand_exclusive(b.m_data, n.m_data, rand_func);
299299
return b;
300300
}
301301

@@ -304,7 +304,7 @@ class BigInt : public Object {
304304
}
305305

306306
private:
307-
bigint data[1];
307+
bigint m_data[1];
308308
};
309309

310310
}

0 commit comments

Comments
 (0)