2 ent-mpc.h -- Numeric types for SXEmacs
3 Copyright (C) 2005, 2006 Sebastian Freundt
5 Author: Sebastian Freundt
7 This file is part of SXEmacs
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.
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.
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/>. */
23 #ifndef INCLUDED_number_mpc_h_
24 #define INCLUDED_number_mpc_h_
27 /* Uno complains about several inline functions that include conditions with
28 assignments and side effects if we don't do this */
43 struct lrecord_header lheader;
46 typedef struct Lisp_Bigc Lisp_Bigc;
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)
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)
60 #define XBIGC_RE(x) bigc_re(XBIGC_DATA(x))
61 #define XBIGC_IM(x) bigc_im(XBIGC_DATA(x))
63 #define BIGC_ARITH_RETURN(f,op) do \
65 Lisp_Object retval = make_bigc_bc(XBIGC_DATA(f)); \
66 bigc_##op(XBIGC_DATA(retval), XBIGC_DATA(f)); \
70 #define BIGC_ARITH_RETURN1(f,op,arg) do \
72 Lisp_Object retval = make_bigc_bc(XBIGC_DATA(f)); \
73 bigc_##op(XBIGC_DATA(retval), XBIGC_DATA(f), arg); \
77 #define BIGC_INIT_PREC(f, prec) do \
79 bigc_init_prec(f, internal_get_precision(prec)); \
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);
86 extern bigc ent_scratch_bigc;
89 /********************************* Bigcs ********************************/
92 /***** Bigc: basic functions *****/
93 #if defined(HAVE_MPC_INIT) && HAVE_MPC_INIT
94 #define bigc_init(f) mpc_init(f)
96 #define bigc_init(f) mpc_init2((f),internal_get_precision(Qnil))
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()
109 /***** Bigc: conversions *****/
110 extern Bufbyte *bigc_to_string(bigc, int);
112 /***** Bigc: converting assignments *****/
113 #define bigc_set(f1, f2) mpc_set(f1, f2, GMP_RNDN)
114 #define bigc_set_long(f, l) mpc_set_si(f, l, GMP_RNDN)
115 #define bigc_set_ulong(f, l) mpc_set_ui(f, l, GMP_RNDN)
117 #define bigc_set_fpfloat(f, d) mpc_set_d(f, d, GMP_RNDN)
118 #define bigc_set_fpfloat_fpfloat(f, d1, d2) \
119 mpc_set_d_d(f, d1, d2, GMP_RNDN)
120 #elif fpfloat_long_double_p
121 #define bigc_set_fpfloat(f, d) mpc_set_d(f, (double)d, GMP_RNDN)
122 #define bigc_set_fpfloat_fpfloat(f, d1, d2) \
123 mpc_set_d_d(f, (double)d1, (double)d2, GMP_RNDN)
125 #define bigc_set_ulong_ulong(f,u1,u2) mpc_set_ui_ui(f, u1, u2, GMP_RNDN)
126 #define bigc_set_long_long(f, l1, l2) mpc_set_si_si(f, l1, l2, GMP_RNDN)
127 #define bigc_set_bigfr(c, bf) do \
129 mpc_set_ui_ui(c, 0UL, 0UL, GMP_RNDN); \
130 mpc_add_fr(c, c, bf, GMP_RNDN); \
132 #define bigc_set_bigfr_bigfr(c, bf1, bf2) do \
134 mpc_set_ui_fr(c, 0UL, bf2, GMP_RNDN); \
135 mpc_add_fr(c, c, bf1, GMP_RNDN); \
138 #if defined mpc_realref
139 #define bigc_re(z) mpc_realref(z)
140 #define bigc_im(z) mpc_imagref(z)
142 #define bigc_re(z) MPC_RE(z)
143 #define bigc_im(z) MPC_IM(z)
146 /***** Bigc: comparisons *****/
147 #define bigc_cmp(f1,f2) mpc_cmp(f1, f2)
148 #define bigc_eq(f1,f2) \
149 (bigfr_eq(bigc_re(f1), bigc_re(f2)) && \
150 bigfr_eq(bigc_im(f1), bigc_im(f2)))
152 /***** Bigc: arithmetic *****/
153 #define bigc_neg(f,f2) mpc_neg(f, f2, GMP_RNDN)
154 #define bigc_abs(f,f2) mpc_abs(f, f2, GMP_RNDN)
155 #define bigc_norm(fr,c) mpc_norm(fr, c, GMP_RNDN)
156 #define bigc_conj(c,c2) mpc_conj(c, c2, GMP_RNDN)
157 #define bigc_add(res,f1,f2) mpc_add(res, f1, f2, GMP_RNDN)
158 #define bigc_sub(res,f1,f2) mpc_sub(res, f1, f2, GMP_RNDN)
159 #define bigc_mul(res,f1,f2) mpc_mul(res, f1, f2, GMP_RNDN)
160 #define bigc_div(res,f1,f2) mpc_div(res, f1, f2, GMP_RNDN)
162 #define bigc_sqrt(res,f) mpc_sqrt(res, f, GMP_RNDN)
164 extern void bigc_pow(bigc, bigc, unsigned long);
166 /* Advanced functions */
167 #define bigc_exp(res, f) mpc_exp(res, f, GMP_RNDN);
169 /* indefinite handling */
170 extern int bigc_nan_p(bigc);
171 extern int bigc_inf_p(bigc);
173 extern Lisp_Object read_bigc_string(char*);
175 extern void init_optables_BIGC_T(void);
176 extern void init_ent_mpc(void);
177 extern void syms_of_ent_mpc(void);
178 extern void vars_of_ent_mpc(void);
180 #endif /* INCLUDED_number_mpc_h_ */