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/* 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 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/. */293031#include <stdio.h>32#include "gmp.h"33#include "expr-impl.h"343536static int37e_mpq_ulong_p (mpq_srcptr q)38{39return mpz_fits_ulong_p (mpq_numref (q))40&& mpz_cmp_ui (mpq_denref (q), 1L) == 0;41}4243/* get value as a ui, on the assumption it fits */44static int45e_mpq_get_ui_fits (mpq_srcptr q)46{47return mpz_get_ui (mpq_numref (q));48}4950static void51e_mpq_set_si1 (mpq_ptr q, long num)52{53mpq_set_si (q, num, 1L);54}5556/* The same as mpz, but putting the result in the numerator. Negatives and57fractions aren't parsed here because '-' and '/' are operators. */58static size_t59e_mpq_number (mpq_ptr res, const char *e, size_t elen, int base)60{61mpz_set_ui (mpq_denref (res), 1L);62return mpexpr_mpz_number (mpq_numref (res), e, elen, base);63}646566/* ignoring prec */67static void68e_mpq_init (mpq_ptr q, unsigned long prec)69{70mpq_init (q);71}7273int74mpq_expr_a (const struct mpexpr_operator_t *table,75mpq_ptr res, int base,76const char *e, size_t elen,77mpq_srcptr var[26])78{79struct mpexpr_parse_t p;8081p.table = table;82p.res = (mpX_ptr) res;83p.base = base;84p.e = e;85p.elen = elen;86p.var = (mpX_srcptr *) var;8788p.mpX_clear = (mpexpr_fun_one_t) mpq_clear;89p.mpX_ulong_p = (mpexpr_fun_i_unary_t) e_mpq_ulong_p;90p.mpX_get_ui = (mpexpr_fun_get_ui_t) e_mpq_get_ui_fits;91p.mpX_init = (mpexpr_fun_unary_ui_t) e_mpq_init;92p.mpX_number = (mpexpr_fun_number_t) e_mpq_number;93p.mpX_set = (mpexpr_fun_unary_t) mpq_set;94p.mpX_set_or_swap = (mpexpr_fun_unary_t) mpq_swap;95p.mpX_set_si = (mpexpr_fun_set_si_t) e_mpq_set_si1;96p.mpX_swap = (mpexpr_fun_swap_t) mpq_swap;9798return mpexpr_evaluate (&p);99}100101102