Build Fix -- compatibility issue with newer autoconf
[sxemacs] / src / ent / ent-mpc.h
1 /*
2   ent-mpc.h -- Numeric types for SXEmacs
3   Copyright (C) 2005, 2006 Sebastian Freundt
4
5   Author:  Sebastian Freundt
6
7 This file is part of SXEmacs
8
9 SXEmacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 SXEmacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
21
22
23 #ifndef INCLUDED_number_mpc_h_
24 #define INCLUDED_number_mpc_h_
25
26 #ifdef UNO
27 /* Uno complains about several inline functions that include conditions with
28    assignments and side effects if we don't do this */
29 #undef __GNUC__
30 #endif
31
32 #ifdef HAVE_MPFR_H
33 # include "mpfr.h"
34 #endif
35 #include "mpc.h"
36
37
38 typedef mpc_t bigc;
39
40 \f
41 struct Lisp_Bigc
42 {
43         struct lrecord_header lheader;
44         bigc data;
45 };
46 typedef struct Lisp_Bigc Lisp_Bigc;
47
48 DECLARE_LRECORD(bigc, Lisp_Bigc);
49 #define XBIGC(x) XRECORD(x, bigc, Lisp_Bigc)
50 #define wrap_bigc(p) wrap_object(p)
51 #define BIGCP(x) RECORDP(x, bigc)
52 #define CHECK_BIGC(x) CHECK_RECORD(x, bigc)
53 #define CONCHECK_BIGC(x) CONCHECK_RECORD(x, bigc)
54
55 #define bigc_data(f) ((f)->data)
56 #define XBIGC_DATA(x) bigc_data(XBIGC(x))
57 #define XBIGC_GET_PREC(x) bigc_get_prec(XBIGC_DATA(x))
58 #define XBIGC_SET_PREC(x,p) bigc_set_prec(XBIGC_DATA(x), p)
59
60 #define XBIGC_RE(x) bigc_re(XBIGC_DATA(x))
61 #define XBIGC_IM(x) bigc_im(XBIGC_DATA(x))
62
63 #define BIGC_ARITH_RETURN(f,op) do                                      \
64 {                                                                       \
65         Lisp_Object retval = make_bigc_bc(XBIGC_DATA(f));               \
66         bigc_##op(XBIGC_DATA(retval), XBIGC_DATA(f));                   \
67         return retval;                                                  \
68 } while (0)
69
70 #define BIGC_ARITH_RETURN1(f,op,arg) do                                 \
71 {                                                                       \
72         Lisp_Object retval = make_bigc_bc(XBIGC_DATA(f));               \
73         bigc_##op(XBIGC_DATA(retval), XBIGC_DATA(f), arg);              \
74         return retval;                                                  \
75 } while (0)
76
77 #define BIGC_INIT_PREC(f, prec) do                                      \
78 {                                                                       \
79         bigc_init_prec(f, internal_get_precision(prec));                \
80 } while (0)
81
82 extern Lisp_Object make_bigc(fpfloat, fpfloat, unsigned long);
83 extern Lisp_Object make_bigc_bfr(bigfr, bigfr, unsigned long);
84 extern Lisp_Object make_bigc_bc(bigc);
85
86 extern bigc ent_scratch_bigc;
87
88 \f
89 /********************************* Bigcs ********************************/
90
91
92 /***** Bigc: basic functions *****/
93 #if defined(HAVE_MPC_INIT) && HAVE_MPC_INIT
94 #define bigc_init(f)                mpc_init(f)
95 #else
96 #define bigc_init(f)                mpc_init2((f),internal_get_precision(Qnil))
97 #endif
98 #define bigc_init_prec(f,prec)      mpc_init2((f), (prec))
99 #define bigc_init_2prec(f,p1,p2)    mpc_init3((f), (p1), (p2))
100 #define bigc_fini(f)                mpc_clear(f)
101 #define bigc_hashcode(f)            (bigfr_hashcode(bigc_re(f)) ^ \
102                                      bigfr_hashcode(bigc_im(f)))
103 #define bigc_get_prec(f)            max(bigfr_get_prec(bigc_re(f)), \
104                                         bigfr_get_prec(bigc_im(f)))
105 #define bigc_set_prec(f, prec)      mpc_set_prec((f), (prec))
106 #define bigc_set_default_prec(prec) mpc_set_default_prec((prec))
107 #define bigc_get_default_prec()     mpc_get_default_prec()
108
109 /***** Bigc: conversions *****/
110 extern Bufbyte *bigc_to_string(bigc, int);
111
112 /***** Bigc: converting assignments *****/
113 #if ! defined(HAVE_MPC_SET_UI_FR) || ! HAVE_MPC_SET_UI_FR
114 #if defined(MPC_SET_X_Y)
115 int mpc_set_ui_fr (mpc_t rop, unsigned long int re, mpfr_t im, mpc_rnd_t rnd);
116 #else
117 #error Cannot derived mpc_set_ui_fr without MPC_SET_X_Y!
118 #endif
119 #endif
120
121 #define bigc_set(f1, f2)                mpc_set(f1, f2, GMP_RNDN)
122 #define bigc_set_long(f, l)             mpc_set_si(f, l, GMP_RNDN)
123 #define bigc_set_ulong(f, l)            mpc_set_ui(f, l, GMP_RNDN)
124 #if fpfloat_double_p
125 #define bigc_set_fpfloat(f, d)          mpc_set_d(f, d, GMP_RNDN)
126 #define bigc_set_fpfloat_fpfloat(f, d1, d2)     \
127         mpc_set_d_d(f, d1, d2, GMP_RNDN)
128 #elif fpfloat_long_double_p
129 #define bigc_set_fpfloat(f, d)          mpc_set_d(f, (double)d, GMP_RNDN)
130 #define bigc_set_fpfloat_fpfloat(f, d1, d2)     \
131         mpc_set_d_d(f, (double)d1, (double)d2, GMP_RNDN)
132 #endif
133 #define bigc_set_ulong_ulong(f,u1,u2)   mpc_set_ui_ui(f, u1, u2, GMP_RNDN)
134 #define bigc_set_long_long(f, l1, l2)   mpc_set_si_si(f, l1, l2, GMP_RNDN)
135 #define bigc_set_bigfr(c, bf) do                                        \
136 {                                                                       \
137         mpc_set_ui_ui(c, 0UL, 0UL, GMP_RNDN);                           \
138         mpc_add_fr(c, c, bf, GMP_RNDN);                                 \
139 } while (0)
140 #define bigc_set_bigfr_bigfr(c, bf1, bf2) do                            \
141 {                                                                       \
142         mpc_set_ui_fr(c, 0UL, bf2, GMP_RNDN);                           \
143         mpc_add_fr(c, c, bf1, GMP_RNDN);                                \
144 } while (0)
145
146 #if defined mpc_realref
147 #define bigc_re(z)                  mpc_realref(z)
148 #define bigc_im(z)                  mpc_imagref(z)
149 #else
150 #define bigc_re(z)                  MPC_RE(z)
151 #define bigc_im(z)                  MPC_IM(z)
152 #endif
153
154 /***** Bigc: comparisons *****/
155 #define bigc_cmp(f1,f2)             mpc_cmp(f1, f2)
156 #define bigc_eq(f1,f2)                                                  \
157         (bigfr_eq(bigc_re(f1), bigc_re(f2)) &&                          \
158          bigfr_eq(bigc_im(f1), bigc_im(f2)))
159
160 /***** Bigc: arithmetic *****/
161 #define bigc_neg(f,f2)              mpc_neg(f, f2, GMP_RNDN)
162 #define bigc_abs(f,f2)              mpc_abs(f, f2, GMP_RNDN)
163 #define bigc_norm(fr,c)             mpc_norm(fr, c, GMP_RNDN)
164 #define bigc_conj(c,c2)             mpc_conj(c, c2, GMP_RNDN)
165 #define bigc_add(res,f1,f2)         mpc_add(res, f1, f2, GMP_RNDN)
166 #define bigc_sub(res,f1,f2)         mpc_sub(res, f1, f2, GMP_RNDN)
167 #define bigc_mul(res,f1,f2)         mpc_mul(res, f1, f2, GMP_RNDN)
168 #define bigc_div(res,f1,f2)         mpc_div(res, f1, f2, GMP_RNDN)
169
170 #define bigc_sqrt(res,f)            mpc_sqrt(res, f, GMP_RNDN)
171
172 extern void bigc_pow(bigc, bigc, unsigned long);
173
174 /* Advanced functions */
175 #define bigc_exp(res, f)            mpc_exp(res, f, GMP_RNDN);
176
177 /* indefinite handling */
178 extern int bigc_nan_p(bigc);
179 extern int bigc_inf_p(bigc);
180
181 extern Lisp_Object read_bigc_string(char*);
182
183 extern void init_optables_BIGC_T(void);
184 extern void init_ent_mpc(void);
185 extern void syms_of_ent_mpc(void);
186 extern void vars_of_ent_mpc(void);
187
188 #endif /* INCLUDED_number_mpc_h_ */