Skip to content

Commit a2e3838

Browse files
committed
py: Clean up and comment out unused functions in mpz.
1 parent 2af921f commit a2e3838

2 files changed

Lines changed: 20 additions & 30 deletions

File tree

py/mpz.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,9 @@ bool mpz_is_zero(const mpz_t *z) {
803803
return z->len == 0;
804804
}
805805

806+
#if 0
807+
these functions are unused
808+
806809
bool mpz_is_pos(const mpz_t *z) {
807810
return z->len > 0 && z->neg == 0;
808811
}
@@ -818,6 +821,7 @@ bool mpz_is_odd(const mpz_t *z) {
818821
bool mpz_is_even(const mpz_t *z) {
819822
return z->len == 0 || (z->dig[0] & 1) == 0;
820823
}
824+
#endif
821825

822826
int mpz_cmp(const mpz_t *z1, const mpz_t *z2) {
823827
// to catch comparison of -0 with +0
@@ -921,6 +925,17 @@ mpz_t *mpz_pow(const mpz_t *lhs, const mpz_t *rhs) {
921925
mpz_pow_inpl(z, lhs, rhs);
922926
return z;
923927
}
928+
929+
/* computes new integers in quo and rem such that:
930+
quo * rhs + rem = lhs
931+
0 <= rem < rhs
932+
can have lhs, rhs the same
933+
*/
934+
void mpz_divmod(const mpz_t *lhs, const mpz_t *rhs, mpz_t **quo, mpz_t **rem) {
935+
*quo = mpz_zero();
936+
*rem = mpz_zero();
937+
mpz_divmod_inpl(*quo, *rem, lhs, rhs);
938+
}
924939
#endif
925940

926941
/* computes dest = abs(z)
@@ -1205,7 +1220,7 @@ void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
12051220
mpz_set_from_int(dest, 1);
12061221

12071222
while (n->len > 0) {
1208-
if (mpz_is_odd(n)) {
1223+
if ((n->dig[0] & 1) != 0) {
12091224
mpz_mul_inpl(dest, dest, x);
12101225
}
12111226
n->len = mpn_shr(n->dig, n->dig, n->len, 1);
@@ -1219,6 +1234,9 @@ void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
12191234
mpz_free(n);
12201235
}
12211236

1237+
#if 0
1238+
these functions are unused
1239+
12221240
/* computes gcd(z1, z2)
12231241
based on Knuth's modified gcd algorithm (I think?)
12241242
gcd(z1, z2) >= 0
@@ -1294,17 +1312,7 @@ mpz_t *mpz_lcm(const mpz_t *z1, const mpz_t *z2) {
12941312
rem->neg = 0;
12951313
return rem;
12961314
}
1297-
1298-
/* computes new integers in quo and rem such that:
1299-
quo * rhs + rem = lhs
1300-
0 <= rem < rhs
1301-
can have lhs, rhs the same
1302-
*/
1303-
void mpz_divmod(const mpz_t *lhs, const mpz_t *rhs, mpz_t **quo, mpz_t **rem) {
1304-
*quo = mpz_zero();
1305-
*rem = mpz_zero();
1306-
mpz_divmod_inpl(*quo, *rem, lhs, rhs);
1307-
}
1315+
#endif
13081316

13091317
/* computes new integers in quo and rem such that:
13101318
quo * rhs + rem = lhs

py/mpz.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,8 @@ void mpz_set_from_float(mpz_t *z, mp_float_t src);
102102
mp_uint_t mpz_set_from_str(mpz_t *z, const char *str, mp_uint_t len, bool neg, mp_uint_t base);
103103

104104
bool mpz_is_zero(const mpz_t *z);
105-
bool mpz_is_pos(const mpz_t *z);
106-
bool mpz_is_neg(const mpz_t *z);
107-
bool mpz_is_odd(const mpz_t *z);
108-
bool mpz_is_even(const mpz_t *z);
109-
110105
int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
111106

112-
mpz_t *mpz_abs(const mpz_t *z);
113-
mpz_t *mpz_neg(const mpz_t *z);
114-
mpz_t *mpz_add(const mpz_t *lhs, const mpz_t *rhs);
115-
mpz_t *mpz_sub(const mpz_t *lhs, const mpz_t *rhs);
116-
mpz_t *mpz_mul(const mpz_t *lhs, const mpz_t *rhs);
117-
mpz_t *mpz_pow(const mpz_t *lhs, const mpz_t *rhs);
118-
119107
void mpz_abs_inpl(mpz_t *dest, const mpz_t *z);
120108
void mpz_neg_inpl(mpz_t *dest, const mpz_t *z);
121109
void mpz_not_inpl(mpz_t *dest, const mpz_t *z);
@@ -128,13 +116,7 @@ void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
128116
void mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
129117
void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
130118
void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
131-
132-
mpz_t *mpz_gcd(const mpz_t *z1, const mpz_t *z2);
133-
mpz_t *mpz_lcm(const mpz_t *z1, const mpz_t *z2);
134-
void mpz_divmod(const mpz_t *lhs, const mpz_t *rhs, mpz_t **quo, mpz_t **rem);
135119
void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs);
136-
mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs);
137-
mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs);
138120

139121
mp_int_t mpz_hash(const mpz_t *z);
140122
bool mpz_as_int_checked(const mpz_t *z, mp_int_t *value);

0 commit comments

Comments
 (0)