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
/* mpf expression evaluation
2
3
Copyright 2000, 2001, 2002 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 <stdio.h>
23
#include <string.h>
24
#include "gmp.h"
25
#include "expr-impl.h"
26
27
28
/* Change this to "#define TRACE(x) x" to get some traces. */
29
#define TRACE(x)
30
31
32
static int
33
e_mpf_sgn (mpf_srcptr x)
34
{
35
return mpf_sgn (x);
36
}
37
38
39
static __gmp_const struct mpexpr_operator_t _mpf_expr_standard_table[] = {
40
41
{ "**", (mpexpr_fun_t) mpf_pow_ui,
42
MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 },
43
44
{ "!", (mpexpr_fun_t) e_mpf_sgn,
45
MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 },
46
{ "-", (mpexpr_fun_t) mpf_neg,
47
MPEXPR_TYPE_UNARY | MPEXPR_TYPE_PREFIX, 210 },
48
49
{ "*", (mpexpr_fun_t) mpf_mul, MPEXPR_TYPE_BINARY, 200 },
50
{ "/", (mpexpr_fun_t) mpf_div, MPEXPR_TYPE_BINARY, 200 },
51
52
{ "+", (mpexpr_fun_t) mpf_add, MPEXPR_TYPE_BINARY, 190 },
53
{ "-", (mpexpr_fun_t) mpf_sub, MPEXPR_TYPE_BINARY, 190 },
54
55
{ "<<", (mpexpr_fun_t) mpf_mul_2exp, MPEXPR_TYPE_BINARY_UI, 180 },
56
{ ">>", (mpexpr_fun_t) mpf_div_2exp, MPEXPR_TYPE_BINARY_UI, 180 },
57
58
{ "<=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LE, 170 },
59
{ "<", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LT, 170 },
60
{ ">=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GE, 170 },
61
{ ">", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GT, 170 },
62
63
{ "==", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_EQ, 160 },
64
{ "!=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_NE, 160 },
65
66
{ "&&", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_AND, 120 },
67
{ "||", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_OR, 110 },
68
69
{ ":", NULL, MPEXPR_TYPE_COLON, 101 },
70
{ "?", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_QUESTION, 100 },
71
72
{ ")", NULL, MPEXPR_TYPE_CLOSEPAREN, 4 },
73
{ "(", NULL, MPEXPR_TYPE_OPENPAREN, 3 },
74
{ ",", NULL, MPEXPR_TYPE_ARGSEP, 2 },
75
{ "$", NULL, MPEXPR_TYPE_VARIABLE, 1 },
76
77
{ "abs", (mpexpr_fun_t) mpf_abs, MPEXPR_TYPE_UNARY },
78
{ "ceil", (mpexpr_fun_t) mpf_ceil, MPEXPR_TYPE_UNARY },
79
{ "cmp", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_I_BINARY },
80
{ "eq", (mpexpr_fun_t) mpf_eq, MPEXPR_TYPE_I_TERNARY_UI },
81
{ "floor", (mpexpr_fun_t) mpf_floor, MPEXPR_TYPE_UNARY },
82
{ "integer_p",(mpexpr_fun_t) mpf_integer_p, MPEXPR_TYPE_I_UNARY },
83
{ "max", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MAX | MPEXPR_TYPE_PAIRWISE },
84
{ "min", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MIN | MPEXPR_TYPE_PAIRWISE },
85
{ "reldiff", (mpexpr_fun_t) mpf_reldiff, MPEXPR_TYPE_BINARY },
86
{ "sgn", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_I_UNARY },
87
{ "sqrt", (mpexpr_fun_t) mpf_sqrt, MPEXPR_TYPE_UNARY },
88
{ "trunc", (mpexpr_fun_t) mpf_trunc, MPEXPR_TYPE_UNARY },
89
90
{ NULL }
91
};
92
93
__gmp_const struct mpexpr_operator_t * __gmp_const mpf_expr_standard_table
94
= _mpf_expr_standard_table;
95
96
97
int
98
#if HAVE_STDARG
99
mpf_expr (mpf_ptr res, int base, __gmp_const char *e, ...)
100
#else
101
mpf_expr (va_alist)
102
va_dcl
103
#endif
104
{
105
mpf_srcptr var[MPEXPR_VARIABLES];
106
va_list ap;
107
int ret;
108
#if HAVE_STDARG
109
va_start (ap, e);
110
#else
111
mpf_ptr res;
112
int base;
113
__gmp_const char *e;
114
va_start (ap);
115
res = va_arg (ap, mpf_ptr);
116
base = va_arg (ap, int);
117
e = va_arg (ap, __gmp_const char *);
118
#endif
119
120
TRACE (printf ("mpf_expr(): base %d, %s\n", base, e));
121
ret = mpexpr_va_to_var ((void **) var, ap);
122
va_end (ap);
123
124
if (ret != MPEXPR_RESULT_OK)
125
return ret;
126
127
return mpf_expr_a (mpf_expr_standard_table, res, base,
128
mpf_get_prec (res), e, strlen(e), var);
129
}
130
131