py: Factor duplicated function to calculate size of formatted int.
diff --git a/py/mpz.c b/py/mpz.c
index 6415e1d..cceb079 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -645,18 +645,6 @@
#define MIN_ALLOC (2)
-STATIC const uint8_t log_base2_floor[] = {
- 0,
- 0, 1, 1, 2,
- 2, 2, 2, 3,
- 3, 3, 3, 3,
- 3, 3, 3, 4,
- 4, 4, 4, 4,
- 4, 4, 4, 4,
- 4, 4, 4, 4,
- 4, 4, 4, 5
-};
-
void mpz_init_zero(mpz_t *z) {
z->neg = 0;
z->fixed_dig = 0;
@@ -1652,18 +1640,6 @@
}
#endif
-mp_uint_t mpz_as_str_size(const mpz_t *i, mp_uint_t base, const char *prefix, char comma) {
- if (base < 2 || base > 32) {
- return 0;
- }
-
- mp_uint_t num_digits = i->len * DIG_SIZE / log_base2_floor[base] + 1;
- mp_uint_t num_commas = comma ? num_digits / 3: 0;
- mp_uint_t prefix_len = prefix ? strlen(prefix) : 0;
-
- return num_digits + num_commas + prefix_len + 2; // +1 for sign, +1 for null byte
-}
-
#if 0
this function is unused
char *mpz_as_str(const mpz_t *i, mp_uint_t base) {
@@ -1673,7 +1649,7 @@
}
#endif
-// assumes enough space as calculated by mpz_as_str_size
+// assumes enough space as calculated by mp_int_format_size
// returns length of string, not including null byte
mp_uint_t mpz_as_str_inpl(const mpz_t *i, mp_uint_t base, const char *prefix, char base_char, char comma, char *str) {
if (str == NULL || base < 2 || base > 32) {