static value make_bigint(const char *s) { mpz_t m; if (mpz_init_set_str(m, s, 0)) abort(); struct bigint *bi = alloc_bigint(m); free_mpz_temps(); return (value)bi; }
bigint_t init_bigint(unsigned int n, unsigned int size) { unsigned int idx = size-1; bigint_t big = alloc_bigint(size); while (n > 0) { big->digits[idx] = n%10; n /= 10; idx--; } return big; }
bigint_t add(bigint_t a, bigint_t b) { unsigned int size = max(a->size,b->size); bigint_t result = alloc_bigint(size); bigint_t small, large; if (a->size > b->size) { small = b; large = a; } else { small = a; large = b; } for (unsigned i = 0; i < large->size; i++) result->digits[i] = large->digits[i]; for (int i = small->size-1; i >= 0; --i) add_digit(result, i, small->digits[i]); return result; }