GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* mpz expression evaluation12Copyright 2000, 2001, 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 the GNU Lesser General Public License as published by8the Free Software Foundation; either version 2.1 of the License, or (at your9option) any later version.1011The GNU MP Library is distributed in the hope that it will be useful, but12WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY13or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public14License for more details.1516You should have received a copy of the GNU Lesser General Public License17along with the GNU MP Library; see the file COPYING.LIB. If not, write to18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,19MA 02110-1301, USA. */2021#include <ctype.h>22#include <stdio.h>23#include <string.h>24#include "gmp.h"25#include "expr-impl.h"262728/* No need to parse '-' since that's handled as an operator.29This function also by mpq_expr_a, so it's not static. */30size_t31mpexpr_mpz_number (mpz_ptr res, __gmp_const char *e, size_t elen, int base)32{33char *edup;34size_t i, ret;35int base_effective = (base == 0 ? 10 : base);36void *(*allocate_func) (size_t);37void (*free_func) (void *, size_t);3839i = 0;40if (e[i] == '0')41{42i++;43if (e[i] == 'x' || e[i] == 'b')44i++;45}4647for ( ; i < elen; i++)48if (! isasciidigit_in_base (e[i], base_effective))49break;5051mp_get_memory_functions (&allocate_func, NULL, &free_func);52edup = (*allocate_func) (i+1);53memcpy (edup, e, i);54edup[i] = '\0';5556if (mpz_set_str (res, edup, base) == 0)57ret = i;58else59ret = 0;6061(*free_func) (edup, i+1);62return ret;63}6465/* ignoring prec */66static void67e_mpz_init (mpz_ptr z, unsigned long prec)68{69mpz_init (z);70}7172int73mpz_expr_a (__gmp_const struct mpexpr_operator_t *table,74mpz_ptr res, int base,75__gmp_const char *e, size_t elen,76mpz_srcptr var[26])77{78struct mpexpr_parse_t p;7980p.table = table;81p.res = (mpX_ptr) res;82p.base = base;83p.e = e;84p.elen = elen;85p.var = (mpX_srcptr *) var;8687p.mpX_clear = (mpexpr_fun_one_t) mpz_clear;88p.mpX_ulong_p = (mpexpr_fun_i_unary_t) mpz_fits_ulong_p;89p.mpX_get_ui = (mpexpr_fun_get_ui_t) mpz_get_ui;90p.mpX_init = (mpexpr_fun_unary_ui_t) e_mpz_init;91p.mpX_number = (mpexpr_fun_number_t) mpexpr_mpz_number;92p.mpX_set = (mpexpr_fun_unary_t) mpz_set;93p.mpX_set_or_swap = (mpexpr_fun_unary_t) mpz_swap;94p.mpX_set_si = (mpexpr_fun_set_si_t) mpz_set_si;95p.mpX_swap = (mpexpr_fun_swap_t) mpz_swap;9697return mpexpr_evaluate (&p);98}99100101