GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* mpq expression evaluation12Copyright 2000, 2001, 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. */202122#include <stdio.h>23#include "gmp.h"24#include "expr-impl.h"252627static int28e_mpq_ulong_p (mpq_srcptr q)29{30return mpz_fits_ulong_p (mpq_numref (q))31&& mpz_cmp_ui (mpq_denref (q), 1L) == 0;32}3334/* get value as a ui, on the assumption it fits */35static int36e_mpq_get_ui_fits (mpq_srcptr q)37{38return mpz_get_ui (mpq_numref (q));39}4041static void42e_mpq_set_si1 (mpq_ptr q, long num)43{44mpq_set_si (q, num, 1L);45}4647/* The same as mpz, but putting the result in the numerator. Negatives and48fractions aren't parsed here because '-' and '/' are operators. */49static size_t50e_mpq_number (mpq_ptr res, __gmp_const char *e, size_t elen, int base)51{52mpz_set_ui (mpq_denref (res), 1L);53return mpexpr_mpz_number (mpq_numref (res), e, elen, base);54}555657/* ignoring prec */58static void59e_mpq_init (mpq_ptr q, unsigned long prec)60{61mpq_init (q);62}6364int65mpq_expr_a (__gmp_const struct mpexpr_operator_t *table,66mpq_ptr res, int base,67__gmp_const char *e, size_t elen,68mpq_srcptr var[26])69{70struct mpexpr_parse_t p;7172p.table = table;73p.res = (mpX_ptr) res;74p.base = base;75p.e = e;76p.elen = elen;77p.var = (mpX_srcptr *) var;7879p.mpX_clear = (mpexpr_fun_one_t) mpq_clear;80p.mpX_ulong_p = (mpexpr_fun_i_unary_t) e_mpq_ulong_p;81p.mpX_get_ui = (mpexpr_fun_get_ui_t) e_mpq_get_ui_fits;82p.mpX_init = (mpexpr_fun_unary_ui_t) e_mpq_init;83p.mpX_number = (mpexpr_fun_number_t) e_mpq_number;84p.mpX_set = (mpexpr_fun_unary_t) mpq_set;85p.mpX_set_or_swap = (mpexpr_fun_unary_t) mpq_swap;86p.mpX_set_si = (mpexpr_fun_set_si_t) e_mpq_set_si1;87p.mpX_swap = (mpexpr_fun_swap_t) mpq_swap;8889return mpexpr_evaluate (&p);90}919293