GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* mpz expression evaluation12Copyright 2000-2002, 2004 Free Software Foundation, Inc.34This file is part of the GNU MP Library.56The GNU MP Library is free software; you can redistribute it and/or modify7it under the terms of either:89* the GNU Lesser General Public License as published by the Free10Software Foundation; either version 3 of the License, or (at your11option) any later version.1213or1415* the GNU General Public License as published by the Free Software16Foundation; either version 2 of the License, or (at your option) any17later version.1819or both in parallel, as here.2021The GNU MP Library is distributed in the hope that it will be useful, but22WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY23or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License24for more details.2526You should have received copies of the GNU General Public License and the27GNU Lesser General Public License along with the GNU MP Library. If not,28see https://www.gnu.org/licenses/. */2930#include <ctype.h>31#include <stdio.h>32#include <string.h>33#include "gmp.h"34#include "expr-impl.h"353637/* No need to parse '-' since that's handled as an operator.38This function also by mpq_expr_a, so it's not static. */39size_t40mpexpr_mpz_number (mpz_ptr res, const char *e, size_t elen, int base)41{42char *edup;43size_t i, ret;44int base_effective = (base == 0 ? 10 : base);45void *(*allocate_func) (size_t);46void (*free_func) (void *, size_t);4748i = 0;49if (e[i] == '0')50{51i++;52if (e[i] == 'x' || e[i] == 'b')53i++;54}5556for ( ; i < elen; i++)57if (! isasciidigit_in_base (e[i], base_effective))58break;5960mp_get_memory_functions (&allocate_func, NULL, &free_func);61edup = (*allocate_func) (i+1);62memcpy (edup, e, i);63edup[i] = '\0';6465if (mpz_set_str (res, edup, base) == 0)66ret = i;67else68ret = 0;6970(*free_func) (edup, i+1);71return ret;72}7374/* ignoring prec */75static void76e_mpz_init (mpz_ptr z, unsigned long prec)77{78mpz_init (z);79}8081int82mpz_expr_a (const struct mpexpr_operator_t *table,83mpz_ptr res, int base,84const char *e, size_t elen,85mpz_srcptr var[26])86{87struct mpexpr_parse_t p;8889p.table = table;90p.res = (mpX_ptr) res;91p.base = base;92p.e = e;93p.elen = elen;94p.var = (mpX_srcptr *) var;9596p.mpX_clear = (mpexpr_fun_one_t) mpz_clear;97p.mpX_ulong_p = (mpexpr_fun_i_unary_t) mpz_fits_ulong_p;98p.mpX_get_ui = (mpexpr_fun_get_ui_t) mpz_get_ui;99p.mpX_init = (mpexpr_fun_unary_ui_t) e_mpz_init;100p.mpX_number = (mpexpr_fun_number_t) mpexpr_mpz_number;101p.mpX_set = (mpexpr_fun_unary_t) mpz_set;102p.mpX_set_or_swap = (mpexpr_fun_unary_t) mpz_swap;103p.mpX_set_si = (mpexpr_fun_set_si_t) mpz_set_si;104p.mpX_swap = (mpexpr_fun_swap_t) mpz_swap;105106return mpexpr_evaluate (&p);107}108109110