Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/* mpf expression evaluation12Copyright 2000-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 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 <stdio.h>31#include <string.h>32#include "gmp.h"33#include "expr-impl.h"343536/* Change this to "#define TRACE(x) x" to get some traces. */37#define TRACE(x)383940static int41e_mpf_sgn (mpf_srcptr x)42{43return mpf_sgn (x);44}454647static const struct mpexpr_operator_t _mpf_expr_standard_table[] = {4849{ "**", (mpexpr_fun_t) mpf_pow_ui,50MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 },5152{ "!", (mpexpr_fun_t) e_mpf_sgn,53MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 },54{ "-", (mpexpr_fun_t) mpf_neg,55MPEXPR_TYPE_UNARY | MPEXPR_TYPE_PREFIX, 210 },5657{ "*", (mpexpr_fun_t) mpf_mul, MPEXPR_TYPE_BINARY, 200 },58{ "/", (mpexpr_fun_t) mpf_div, MPEXPR_TYPE_BINARY, 200 },5960{ "+", (mpexpr_fun_t) mpf_add, MPEXPR_TYPE_BINARY, 190 },61{ "-", (mpexpr_fun_t) mpf_sub, MPEXPR_TYPE_BINARY, 190 },6263{ "<<", (mpexpr_fun_t) mpf_mul_2exp, MPEXPR_TYPE_BINARY_UI, 180 },64{ ">>", (mpexpr_fun_t) mpf_div_2exp, MPEXPR_TYPE_BINARY_UI, 180 },6566{ "<=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LE, 170 },67{ "<", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LT, 170 },68{ ">=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GE, 170 },69{ ">", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GT, 170 },7071{ "==", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_EQ, 160 },72{ "!=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_NE, 160 },7374{ "&&", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_AND, 120 },75{ "||", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_OR, 110 },7677{ ":", NULL, MPEXPR_TYPE_COLON, 101 },78{ "?", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_QUESTION, 100 },7980{ ")", NULL, MPEXPR_TYPE_CLOSEPAREN, 4 },81{ "(", NULL, MPEXPR_TYPE_OPENPAREN, 3 },82{ ",", NULL, MPEXPR_TYPE_ARGSEP, 2 },83{ "$", NULL, MPEXPR_TYPE_VARIABLE, 1 },8485{ "abs", (mpexpr_fun_t) mpf_abs, MPEXPR_TYPE_UNARY },86{ "ceil", (mpexpr_fun_t) mpf_ceil, MPEXPR_TYPE_UNARY },87{ "cmp", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_I_BINARY },88{ "eq", (mpexpr_fun_t) mpf_eq, MPEXPR_TYPE_I_TERNARY_UI },89{ "floor", (mpexpr_fun_t) mpf_floor, MPEXPR_TYPE_UNARY },90{ "integer_p",(mpexpr_fun_t) mpf_integer_p, MPEXPR_TYPE_I_UNARY },91{ "max", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MAX | MPEXPR_TYPE_PAIRWISE },92{ "min", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MIN | MPEXPR_TYPE_PAIRWISE },93{ "reldiff", (mpexpr_fun_t) mpf_reldiff, MPEXPR_TYPE_BINARY },94{ "sgn", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_I_UNARY },95{ "sqrt", (mpexpr_fun_t) mpf_sqrt, MPEXPR_TYPE_UNARY },96{ "trunc", (mpexpr_fun_t) mpf_trunc, MPEXPR_TYPE_UNARY },9798{ NULL }99};100101const struct mpexpr_operator_t * const mpf_expr_standard_table102= _mpf_expr_standard_table;103104105int106mpf_expr (mpf_ptr res, int base, const char *e, ...)107{108mpf_srcptr var[MPEXPR_VARIABLES];109va_list ap;110int ret;111va_start (ap, e);112113TRACE (printf ("mpf_expr(): base %d, %s\n", base, e));114ret = mpexpr_va_to_var ((void **) var, ap);115va_end (ap);116117if (ret != MPEXPR_RESULT_OK)118return ret;119120return mpf_expr_a (mpf_expr_standard_table, res, base,121mpf_get_prec (res), e, strlen(e), var);122}123124125