1
/* mpf 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,
26
#include "expr-impl.h"
29
/* Change this to "#define TRACE(x) x" to get some traces. */
34
e_mpf_sgn (mpf_srcptr x)
40
static __gmp_const struct mpexpr_operator_t _mpf_expr_standard_table[] = {
42
{ "**", (mpexpr_fun_t) mpf_pow_ui,
43
MPEXPR_TYPE_BINARY_UI | MPEXPR_TYPE_RIGHTASSOC, 220 },
45
{ "!", (mpexpr_fun_t) e_mpf_sgn,
46
MPEXPR_TYPE_LOGICAL_NOT | MPEXPR_TYPE_PREFIX, 210 },
47
{ "-", (mpexpr_fun_t) mpf_neg,
48
MPEXPR_TYPE_UNARY | MPEXPR_TYPE_PREFIX, 210 },
50
{ "*", (mpexpr_fun_t) mpf_mul, MPEXPR_TYPE_BINARY, 200 },
51
{ "/", (mpexpr_fun_t) mpf_div, MPEXPR_TYPE_BINARY, 200 },
53
{ "+", (mpexpr_fun_t) mpf_add, MPEXPR_TYPE_BINARY, 190 },
54
{ "-", (mpexpr_fun_t) mpf_sub, MPEXPR_TYPE_BINARY, 190 },
56
{ "<<", (mpexpr_fun_t) mpf_mul_2exp, MPEXPR_TYPE_BINARY_UI, 180 },
57
{ ">>", (mpexpr_fun_t) mpf_div_2exp, MPEXPR_TYPE_BINARY_UI, 180 },
59
{ "<=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LE, 170 },
60
{ "<", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_LT, 170 },
61
{ ">=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GE, 170 },
62
{ ">", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_GT, 170 },
64
{ "==", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_EQ, 160 },
65
{ "!=", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_CMP_NE, 160 },
67
{ "&&", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_AND, 120 },
68
{ "||", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_LOGICAL_OR, 110 },
70
{ ":", NULL, MPEXPR_TYPE_COLON, 101 },
71
{ "?", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_QUESTION, 100 },
73
{ ")", NULL, MPEXPR_TYPE_CLOSEPAREN, 4 },
74
{ "(", NULL, MPEXPR_TYPE_OPENPAREN, 3 },
75
{ ",", NULL, MPEXPR_TYPE_ARGSEP, 2 },
76
{ "$", NULL, MPEXPR_TYPE_VARIABLE, 1 },
78
{ "abs", (mpexpr_fun_t) mpf_abs, MPEXPR_TYPE_UNARY },
79
{ "ceil", (mpexpr_fun_t) mpf_ceil, MPEXPR_TYPE_UNARY },
80
{ "cmp", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_I_BINARY },
81
{ "eq", (mpexpr_fun_t) mpf_eq, MPEXPR_TYPE_I_TERNARY_UI },
82
{ "floor", (mpexpr_fun_t) mpf_floor, MPEXPR_TYPE_UNARY },
83
{ "integer_p",(mpexpr_fun_t) mpf_integer_p, MPEXPR_TYPE_I_UNARY },
84
{ "max", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MAX | MPEXPR_TYPE_PAIRWISE },
85
{ "min", (mpexpr_fun_t) mpf_cmp, MPEXPR_TYPE_MIN | MPEXPR_TYPE_PAIRWISE },
86
{ "reldiff", (mpexpr_fun_t) mpf_reldiff, MPEXPR_TYPE_BINARY },
87
{ "sgn", (mpexpr_fun_t) e_mpf_sgn, MPEXPR_TYPE_I_UNARY },
88
{ "sqrt", (mpexpr_fun_t) mpf_sqrt, MPEXPR_TYPE_UNARY },
89
{ "trunc", (mpexpr_fun_t) mpf_trunc, MPEXPR_TYPE_UNARY },
94
__gmp_const struct mpexpr_operator_t * __gmp_const mpf_expr_standard_table
95
= _mpf_expr_standard_table;
100
mpf_expr (mpf_ptr res, int base, __gmp_const char *e, ...)
106
mpf_srcptr var[MPEXPR_VARIABLES];
116
res = va_arg (ap, mpf_ptr);
117
base = va_arg (ap, int);
118
e = va_arg (ap, __gmp_const char *);
121
TRACE (printf ("mpf_expr(): base %d, %s\n", base, e));
122
ret = mpexpr_va_to_var ((void **) var, ap);
125
if (ret != MPEXPR_RESULT_OK)
128
return mpf_expr_a (mpf_expr_standard_table, res, base,
129
mpf_get_prec (res), e, strlen(e), var);