1
/* mpz expression evaluation */
4
Copyright 2000, 2001 Free Software Foundation, Inc.
6
This file is part of the GNU MP Library.
8
The GNU MP Library is free software; you can redistribute it and/or modify
9
it under the terms of the GNU Lesser General Public License as published by
10
the Free Software Foundation; either version 2.1 of the License, or (at your
11
option) any later version.
13
The GNU MP Library is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16
License for more details.
18
You should have received a copy of the GNU Lesser General Public License
19
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27
#include "expr-impl.h"
30
/* No need to parse '-' since that's handled as an operator.
31
This function also by mpq_expr_a, so it's not static. */
33
mpexpr_mpz_number (mpz_ptr res, __gmp_const char *e, size_t elen, int base)
37
int base_effective = (base == 0 ? 10 : base);
43
if (e[i] == 'x' || e[i] == 'b')
47
for ( ; i < elen; i++)
48
if (! isasciidigit_in_base (e[i], base_effective))
51
edup = (*__gmp_allocate_func) (i+1);
55
if (mpz_set_str (res, edup, base) == 0)
60
(*__gmp_free_func) (edup, i+1);
66
mpz_expr_a (__gmp_const struct mpexpr_operator_t *table,
67
mpz_ptr res, int base,
68
__gmp_const char *e, size_t elen,
71
struct mpexpr_parse_t p;
74
p.res = (mpX_ptr) res;
78
p.var = (mpX_srcptr *) var;
80
p.mpX_clear = (mpexpr_fun_one_t) mpz_clear;
81
p.mpX_ulong_p = (mpexpr_fun_i_unary_t) mpz_fits_ulong_p;
82
p.mpX_get_ui = (mpexpr_fun_get_ui_t) mpz_get_ui;
83
p.mpX_init = (mpexpr_fun_unary_ui_t) mpz_init;
84
p.mpX_number = (mpexpr_fun_number_t) mpexpr_mpz_number;
85
p.mpX_set = (mpexpr_fun_unary_t) mpz_set;
86
p.mpX_set_or_swap = (mpexpr_fun_unary_t) mpz_swap;
87
p.mpX_set_si = (mpexpr_fun_set_si_t) mpz_set_si;
88
p.mpX_swap = (mpexpr_fun_swap_t) mpz_swap;
90
return mpexpr_evaluate (&p);