Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563728 views
1
/* mpz expression evaluation
2
3
Copyright 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
4
5
This file is part of the GNU MP Library.
6
7
The GNU MP Library is free software; you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 of the License, or (at your
10
option) any later version.
11
12
The GNU MP Library is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
License for more details.
16
17
You should have received a copy of the GNU Lesser General Public License
18
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
MA 02110-1301, USA. */
21
22
#include <ctype.h>
23
#include <stdio.h>
24
#include <string.h>
25
#include "gmp.h"
26
#include "expr-impl.h"
27
28
29
/* No need to parse '-' since that's handled as an operator.
30
This function also by mpq_expr_a, so it's not static. */
31
size_t
32
mpexpr_mpz_number (mpz_ptr res, __gmp_const char *e, size_t elen, int base)
33
{
34
char *edup;
35
size_t i, ret;
36
int base_effective = (base == 0 ? 10 : base);
37
void *(*allocate_func) (size_t);
38
void (*free_func) (void *, size_t);
39
40
i = 0;
41
if (e[i] == '0')
42
{
43
i++;
44
if (e[i] == 'x' || e[i] == 'b')
45
i++;
46
}
47
48
for ( ; i < elen; i++)
49
if (! isasciidigit_in_base (e[i], base_effective))
50
break;
51
52
mp_get_memory_functions (&allocate_func, NULL, &free_func);
53
edup = (*allocate_func) (i+1);
54
memcpy (edup, e, i);
55
edup[i] = '\0';
56
57
if (mpz_set_str (res, edup, base) == 0)
58
ret = i;
59
else
60
ret = 0;
61
62
(*free_func) (edup, i+1);
63
return ret;
64
}
65
66
/* ignoring prec */
67
static void
68
e_mpz_init (mpz_ptr z, unsigned long prec)
69
{
70
mpz_init (z);
71
}
72
73
int
74
mpz_expr_a (__gmp_const struct mpexpr_operator_t *table,
75
mpz_ptr res, int base,
76
__gmp_const char *e, size_t elen,
77
mpz_srcptr var[26])
78
{
79
struct mpexpr_parse_t p;
80
81
p.table = table;
82
p.res = (mpX_ptr) res;
83
p.base = base;
84
p.e = e;
85
p.elen = elen;
86
p.var = (mpX_srcptr *) var;
87
88
p.mpX_clear = (mpexpr_fun_one_t) mpz_clear;
89
p.mpX_ulong_p = (mpexpr_fun_i_unary_t) mpz_fits_ulong_p;
90
p.mpX_get_ui = (mpexpr_fun_get_ui_t) mpz_get_ui;
91
p.mpX_init = (mpexpr_fun_unary_ui_t) e_mpz_init;
92
p.mpX_number = (mpexpr_fun_number_t) mpexpr_mpz_number;
93
p.mpX_set = (mpexpr_fun_unary_t) mpz_set;
94
p.mpX_set_or_swap = (mpexpr_fun_unary_t) mpz_swap;
95
p.mpX_set_si = (mpexpr_fun_set_si_t) mpz_set_si;
96
p.mpX_swap = (mpexpr_fun_swap_t) mpz_swap;
97
98
return mpexpr_evaluate (&p);
99
}
100
101