[BACK]Return to expr-impl.h CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / demos / expr

Annotation of OpenXM_contrib/gmp/demos/expr/expr-impl.h, Revision 1.1.1.1

1.1       ohara       1: /* Implementation specifics for 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., 59 Temple Place - Suite 330, Boston,
                     20: MA 02111-1307, USA. */
                     21:
                     22:
                     23: #include "expr-config.h"
                     24:
                     25:
                     26: /* Same tests as gmp.h. */
                     27: #if  defined (__STDC__)                                 \
                     28:   || defined (__cplusplus)                              \
                     29:   || defined (_AIX)                                     \
                     30:   || (defined (__mips) && defined (_SYSTYPE_SVR4))      \
                     31:   || defined (_MSC_VER)                                 \
                     32:   || defined(_WIN32)
                     33: #define HAVE_STDARG 1
                     34: #include <stdarg.h>
                     35: #else
                     36: #define HAVE_STDARG 0
                     37: #include <varargs.h>
                     38: #endif
                     39:
                     40: #if HAVE_MPFR
                     41: #include "mpfr.h"
                     42: #endif
                     43:
                     44: #include "expr.h"
                     45:
                     46:
                     47: /* Rouding mode for mpfr_expr.  Change as desired.  */
                     48: #define ROUND  GMP_RNDZ
                     49:
                     50:
                     51: #define isasciidigit(c)   (isascii (c) && isdigit (c))
                     52: #define isasciicsym(c)    (isascii (c) && (isalnum(c) || (c) == '_'))
                     53:
                     54: #define isasciidigit_in_base(c,base)                    \
                     55:   (isascii (c)                                          \
                     56:    && ((isdigit (c) && (c)-'0' < (base))                \
                     57:        || (isupper (c) && (c)-'A'+10 < (base))          \
                     58:        || (islower (c) && (c)-'a'+10 < (base))))
                     59:
                     60:
                     61: union mpX_t {
                     62:   mpz_t   z;
                     63:   mpq_t   q;
                     64:   mpf_t   f;
                     65: #if HAVE_MPFR
                     66:   mpfr_t  r;
                     67: #endif
                     68: };
                     69:
                     70: typedef union mpX_t *mpX_ptr;
                     71: typedef __gmp_const union mpX_t *mpX_srcptr;
                     72:
                     73: typedef void (*mpexpr_fun_one_t) __GMP_PROTO ((mpX_ptr));
                     74: typedef unsigned long (*mpexpr_fun_ui_one_t) __GMP_PROTO ((mpX_ptr));
                     75:
                     76: typedef void (*mpexpr_fun_0ary_t) __GMP_PROTO ((mpX_ptr));
                     77: typedef int  (*mpexpr_fun_i_0ary_t) __GMP_PROTO ((void));
                     78:
                     79: typedef void (*mpexpr_fun_unary_t) __GMP_PROTO ((mpX_ptr, mpX_srcptr));
                     80: typedef void (*mpexpr_fun_unary_ui_t) __GMP_PROTO ((mpX_ptr, unsigned long));
                     81: typedef int  (*mpexpr_fun_i_unary_t) __GMP_PROTO ((mpX_srcptr));
                     82: typedef int  (*mpexpr_fun_i_unary_ui_t) __GMP_PROTO ((unsigned long));
                     83:
                     84: typedef void (*mpexpr_fun_binary_t) __GMP_PROTO ((mpX_ptr, mpX_srcptr, mpX_srcptr));
                     85: typedef void (*mpexpr_fun_binary_ui_t) __GMP_PROTO ((mpX_ptr, mpX_srcptr, unsigned long));
                     86: typedef int  (*mpexpr_fun_i_binary_t) __GMP_PROTO ((mpX_srcptr, mpX_srcptr));
                     87: typedef int  (*mpexpr_fun_i_binary_ui_t) __GMP_PROTO ((mpX_srcptr, unsigned long));
                     88:
                     89: typedef void (*mpexpr_fun_ternary_t)
                     90:      __GMP_PROTO ((mpX_ptr, mpX_srcptr, mpX_srcptr, mpX_srcptr));
                     91: typedef void (*mpexpr_fun_ternary_ui_t)
                     92:      __GMP_PROTO ((mpX_ptr, mpX_srcptr, mpX_srcptr, unsigned long));
                     93: typedef int (*mpexpr_fun_i_ternary_t)
                     94:      __GMP_PROTO ((mpX_srcptr, mpX_srcptr, mpX_srcptr));
                     95: typedef int (*mpexpr_fun_i_ternary_ui_t)
                     96:      __GMP_PROTO ((mpX_srcptr, mpX_srcptr, unsigned long));
                     97:
                     98: typedef size_t (*mpexpr_fun_number_t)
                     99:      __GMP_PROTO ((mpX_ptr, __gmp_const char *str, size_t len, int base));
                    100: typedef void (*mpexpr_fun_swap_t) __GMP_PROTO ((mpX_ptr, mpX_ptr));
                    101: typedef unsigned long (*mpexpr_fun_get_ui_t) __GMP_PROTO ((mpX_srcptr));
                    102: typedef void (*mpexpr_fun_set_si_t) __GMP_PROTO ((mpX_srcptr, long));
                    103:
                    104: struct mpexpr_control_t {
                    105:   __gmp_const struct mpexpr_operator_t  *op;
                    106:   int                                   argcount;
                    107: };
                    108:
                    109: #define MPEXPR_VARIABLES  26
                    110:
                    111: struct mpexpr_parse_t {
                    112:   __gmp_const struct mpexpr_operator_t  *table;
                    113:
                    114:   mpX_ptr                               res;
                    115:   int                                   base;
                    116:   unsigned long                         prec;
                    117:   __gmp_const char                      *e;
                    118:   size_t                                elen;
                    119:   mpX_srcptr                            *var;
                    120:   int                                   error_code;
                    121:
                    122:   int                                   token;
                    123:   __gmp_const struct mpexpr_operator_t  *token_op;
                    124:
                    125:   union mpX_t                           *data_stack;
                    126:   int                                   data_top;
                    127:   int                                   data_alloc;
                    128:   int                                   data_inited;
                    129:
                    130:   struct mpexpr_control_t               *control_stack;
                    131:   int                                   control_top;
                    132:   int                                   control_alloc;
                    133:
                    134:
                    135:   mpexpr_fun_0ary_t                     mpX_clear;
                    136:   mpexpr_fun_i_unary_t                  mpX_ulong_p;
                    137:   mpexpr_fun_get_ui_t                   mpX_get_ui;
                    138:   mpexpr_fun_unary_ui_t                 mpX_init;
                    139:   mpexpr_fun_number_t                   mpX_number;
                    140:   mpexpr_fun_unary_t                    mpX_set;
                    141:   mpexpr_fun_unary_t                    mpX_set_or_swap;
                    142:   mpexpr_fun_set_si_t                   mpX_set_si;
                    143:   mpexpr_fun_swap_t                     mpX_swap;
                    144: };
                    145:
                    146:
                    147: int mpexpr_evaluate __GMP_PROTO ((struct mpexpr_parse_t *p));
                    148: int mpexpr_va_to_var __GMP_PROTO ((void *var[], va_list ap));
                    149: size_t mpexpr_mpz_number __GMP_PROTO ((mpz_ptr res,
                    150:                                   __gmp_const char *e, size_t elen, int base));

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>