GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* mpf expression evaluation12Copyright 2000, 2001, 2002 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 <stdio.h>22#include <string.h>23#include "gmp.h"24#include "expr-impl.h"252627/* Change this to "#define TRACE(x) x" to get some traces. */28#define TRACE(x)293031static int32e_mpf_sgn (mpf_srcptr x)33{34return mpf_sgn (x);35}363738static __gmp_const struct mpexpr_operator_t _mpf_expr_standard_table[] = {3940{ "**", (mpexpr_fun_t) mpf_pow_ui,41MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 },4243{ "!", (mpexpr_fun_t) e_mpf_sgn,44MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 },45{ "-", (mpexpr_fun_t) mpf_neg,46MPEXPR_TYPE_UNARY | MPEXPR_TYPE_PREFIX, 210 },4748{ "*", (mpexpr_fun_t) mpf_mul, MPEXPR_TYPE_BINARY, 200 },49{ "/", (mpexpr_fun_t) mpf_div, MPEXPR_TYPE_BINARY, 200 },5051{ "+", (mpexpr_fun_t) mpf_add, MPEXPR_TYPE_BINARY, 190 },52{ "-", (mpexpr_fun_t) mpf_sub, MPEXPR_TYPE_BINARY, 190 },5354{ "<<", (mpexpr_fun_t) mpf_mul_2exp, MPEXPR_TYPE_BINARY_UI, 180 },55{ ">>", (mpexpr_fun_t) mpf_div_2exp, MPEXPR_TYPE_BINARY_UI, 180 },5657{ "<=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LE, 170 },58{ "<", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LT, 170 },59{ ">=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GE, 170 },60{ ">", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GT, 170 },6162{ "==", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_EQ, 160 },63{ "!=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_NE, 160 },6465{ "&&", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_AND, 120 },66{ "||", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_OR, 110 },6768{ ":", NULL, MPEXPR_TYPE_COLON, 101 },69{ "?", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_QUESTION, 100 },7071{ ")", NULL, MPEXPR_TYPE_CLOSEPAREN, 4 },72{ "(", NULL, MPEXPR_TYPE_OPENPAREN, 3 },73{ ",", NULL, MPEXPR_TYPE_ARGSEP, 2 },74{ "$", NULL, MPEXPR_TYPE_VARIABLE, 1 },7576{ "abs", (mpexpr_fun_t) mpf_abs, MPEXPR_TYPE_UNARY },77{ "ceil", (mpexpr_fun_t) mpf_ceil, MPEXPR_TYPE_UNARY },78{ "cmp", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_I_BINARY },79{ "eq", (mpexpr_fun_t) mpf_eq, MPEXPR_TYPE_I_TERNARY_UI },80{ "floor", (mpexpr_fun_t) mpf_floor, MPEXPR_TYPE_UNARY },81{ "integer_p",(mpexpr_fun_t) mpf_integer_p, MPEXPR_TYPE_I_UNARY },82{ "max", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MAX | MPEXPR_TYPE_PAIRWISE },83{ "min", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MIN | MPEXPR_TYPE_PAIRWISE },84{ "reldiff", (mpexpr_fun_t) mpf_reldiff, MPEXPR_TYPE_BINARY },85{ "sgn", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_I_UNARY },86{ "sqrt", (mpexpr_fun_t) mpf_sqrt, MPEXPR_TYPE_UNARY },87{ "trunc", (mpexpr_fun_t) mpf_trunc, MPEXPR_TYPE_UNARY },8889{ NULL }90};9192__gmp_const struct mpexpr_operator_t * __gmp_const mpf_expr_standard_table93= _mpf_expr_standard_table;949596int97#if HAVE_STDARG98mpf_expr (mpf_ptr res, int base, __gmp_const char *e, ...)99#else100mpf_expr (va_alist)101va_dcl102#endif103{104mpf_srcptr var[MPEXPR_VARIABLES];105va_list ap;106int ret;107#if HAVE_STDARG108va_start (ap, e);109#else110mpf_ptr res;111int base;112__gmp_const char *e;113va_start (ap);114res = va_arg (ap, mpf_ptr);115base = va_arg (ap, int);116e = va_arg (ap, __gmp_const char *);117#endif118119TRACE (printf ("mpf_expr(): base %d, %s\n", base, e));120ret = mpexpr_va_to_var ((void **) var, ap);121va_end (ap);122123if (ret != MPEXPR_RESULT_OK)124return ret;125126return mpf_expr_a (mpf_expr_standard_table, res, base,127mpf_get_prec (res), e, strlen(e), var);128}129130131