Fix build in MacOS after ent changes
[sxemacs] / src / ent / ent-mpfr.c
1 /*
2   ent-mpfr.c -- 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 #include <config.h>
24 #include <limits.h>
25 #include <math.h>
26 #include "lisp.h"
27 #include "sysproc.h"    /* For qxe_getpid */
28
29 #include "ent.h"
30 #include "ent-optable.h"
31 #include "ent-lift.h"
32 #include "ent-indef.h"
33 #include "ent-mpfr.h"
34
35 \f
36 Lisp_Object Veuler;
37 Lisp_Object Veuler_mascheroni;
38 Lisp_Object Vpi;
39
40 bigfr ent_scratch_bigfr;
41 static ase_nullary_operation_f Qent_mpfr_zero, Qent_mpfr_one;
42
43 \f
44 static void
45 bigfr_print(Lisp_Object obj, Lisp_Object printcharfun, int SXE_UNUSED(unused))
46 {
47         Bufbyte *fstr = bigfr_to_string(XBIGFR_DATA(obj), 10);
48         write_c_string((char*)fstr, printcharfun);
49         xfree(fstr);
50         fstr = (Bufbyte *)NULL;
51         return;
52 }
53
54 static int
55 bigfr_equal (Lisp_Object obj1, Lisp_Object obj2, int unused)
56 {
57         return bigfr_eq(XBIGFR_DATA(obj1), XBIGFR_DATA(obj2));
58 }
59
60 static unsigned long
61 bigfr_hash (Lisp_Object obj, int unused)
62 {
63         return bigfr_hashcode(XBIGFR_DATA(obj));
64 }
65
66 static Lisp_Object
67 bigfr_mark (Lisp_Object unused)
68 {
69         return Qnil;
70 }
71
72 static void
73 bigfr_finalise (void *header, int for_disksave)
74 {
75         if (for_disksave)
76                 signal_simple_error
77                         ("Can't dump an emacs containing MPFR objects", Qt);
78
79         /* less warnings */
80         if (header);
81 }
82
83 static const struct lrecord_description bigfr_description[] = {
84         { XD_OPAQUE_DATA_PTR, offsetof(Lisp_Bigfr, data) },
85         { XD_END }
86 };
87
88 DEFINE_BASIC_LRECORD_IMPLEMENTATION("bigfr", bigfr,
89                                     bigfr_mark, bigfr_print, bigfr_finalise,
90                                     bigfr_equal, bigfr_hash,
91                                     bigfr_description, Lisp_Bigfr);
92
93
94 DEFUN ("bigfr-get-precision", Fbigfr_get_precision, 1, 1, 0, /*
95 Return the precision of bigfr F as an integer.
96 */
97        (f))
98 {
99         CHECK_BIGFR(f);
100         return make_integer((signed long)XBIGFR_GET_PREC(f));
101 }
102
103 #ifndef MPFR_PREC_MIN
104 #define MPFR_PREC_MIN 2UL
105 #endif
106
107 DEFUN ("bigfr-set-precision", Fbigfr_set_precision, 2, 2, 0, /*
108 Set the precision of F, a bigfr, to PRECISION, a nonnegative integer.
109 The new precision of F is returned.  Note that the return value may differ
110 from PRECISION if the underlying library is unable to support exactly
111 PRECISION bits of precision.
112 */
113        (f, precision))
114 {
115         unsigned long prec;
116
117         CHECK_BIGFR(f);
118         if (INTP(precision)) {
119                 prec = (XINT(precision) <= 0)
120                         ? MPFR_PREC_MIN : (unsigned long)XINT(precision);
121         }
122 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
123         else if (BIGZP(precision)) {
124                 prec = bigz_fits_ulong_p(XBIGZ_DATA(precision))
125                         ? bigz_to_ulong(XBIGZ_DATA(precision))
126                         : UINT_MAX;
127         }
128 #endif  /* HAVE_MPZ */
129         else {
130                 dead_wrong_type_argument(Qintegerp, f);
131                 return Qnil;
132         }
133
134         XBIGFR_SET_PREC(f, prec);
135         return Fbigfr_get_precision(f);
136 }
137
138 \f
139 Bufbyte *bigfr_to_string(mpfr_t f, int base)
140 {
141         mp_exp_t expt;
142         Bufbyte *str;
143         int len;
144         const int sign = mpfr_sgn(f);
145         const int neg = (sign < 0) ? 1 : 0;
146
147         if (mpfr_inf_p(f)) {
148                 if (sign > 0) {
149                         str = indef_to_string((indef)POS_INFINITY);
150                 } else {
151                         str = indef_to_string((indef)NEG_INFINITY);
152                 }
153                 return str;
154         } else if (mpfr_nan_p(f)) {
155                 str = indef_to_string((indef)NOT_A_NUMBER);
156                 return str;
157         } else {
158                 if (base <= 1)
159                         base = 10;
160
161                 str = (Bufbyte *)mpfr_get_str(NULL, &expt, base, 0, f,
162                                               GMP_RNDN);
163                 len = strlen((char *)str) + 1;  /* Count the null terminator */
164
165                 /* Move digits down to insert a radix point */
166                 if (expt <= 0) {
167                         /* We need room for a radix point and leading zeroes */
168                         const int space = -expt + 2;
169                         xrealloc_array(str, Bufbyte, len + space);
170                         memmove(&str[space + neg], &str[neg], len - neg);
171                         memset(&str[neg], '0', space);
172                         str[neg + 1] = '.';
173                         len += space;
174                 } else if (expt < len) {
175                         /* We just need room for a radix point */
176                         xrealloc_array(str, Bufbyte, len + 1);
177                         memmove(&str[expt + neg + 1],
178                                 &str[expt + neg],
179                                 len - (expt + neg));
180                         str[expt + neg] = '.';
181                         len++;
182                 } else {
183                         /* We need room for trailing zeroes */
184                         xrealloc_array(str, Bufbyte, expt + 1);
185                         memset(&str[len-1], '0', expt+2-len);
186                         str[expt] = '\0';
187                         len = expt + 1;
188                 }
189
190                 return str;
191         }
192 }
193
194 Lisp_Object read_bigfr_string(char *cp)
195 {
196         /* The mpfr version of bigfr_set_string (mpfr_set_str)
197            has the following limitation: if p starts with a '+'
198            sign, it does nothing; i.e., it leaves its bigfloat
199            argument untouched.
200            Therefore, move p past any leading '+' signs. */
201         bigfr bfr;
202         Lisp_Object result;
203
204         bigfr_init_prec(bfr, bigfr_get_default_prec());
205
206         if (*cp == '+')
207                 cp++;
208
209         bigfr_set_string(bfr, (const char*)cp, 0);
210         result = make_bigfr_bfr(bfr);
211
212         bigfr_fini(bfr);
213         return result;
214 }
215
216 #if defined HAVE_MPC && defined WITH_MPC ||     \
217         defined HAVE_PSEUC && defined WITH_PSEUC
218 Lisp_Object read_bigc_string(char *cp)
219 {
220         bigfr bf_re, bf_im;
221         int sign;
222         Lisp_Object result;
223
224         BIGFR_INIT_PREC(bf_re, Qnil);
225         BIGFR_INIT_PREC(bf_im, Qnil);
226
227         /* MPC bigc_set_string has no effect
228          * with initial + sign */
229         if (*cp == '+')
230                 cp++;
231         bigfr_set_string(bf_re, cp, 0);
232
233         if (*cp == '-') {
234                 /* jump over a leading minus */
235                 cp++;
236         }
237
238         while ((*cp >= '0' && *cp <= '9') ||
239                (*cp == '.'))
240                 cp++;
241
242         /* read the imaginary part */
243         sign = 0;
244         if (*cp == '+') {
245                 cp++;
246                 sign = 1;
247         }
248         if (*cp == '-') {
249                 cp++;
250                 sign = -1;
251         }
252         if ((*cp == 'i' || *cp == 'I') &&
253             (sign != 0)) {
254                 /* expand +i to +1i and -i to -1i */
255                 bigfr_set_long(bf_im, 1L);
256         } else if (sign == 0) {
257                 /* obviously we did not have a+bi,
258                  * but merely bi
259                  */
260                 bigfr_set(bf_im, bf_re);
261                 bigfr_set_long(bf_re, 0L);
262         } else {
263                 bigfr_set_string(bf_im, cp, 0);
264         }
265
266         if (sign < 0)
267                 bigfr_neg(bf_im, bf_im);
268
269         result = make_bigc_bfr(bf_re, bf_im,
270                                max(bigfr_get_prec(bf_re),
271                                    bigfr_get_prec(bf_im)));
272
273         bigfr_fini(bf_re);
274         bigfr_fini(bf_im);
275         return result;
276 }
277 #endif
278
279 \f
280 /* bigfr ops */
281 static Lisp_Object
282 ent_sum_BIGFR_T(Lisp_Object l, Lisp_Object r)
283 {
284         bigfr_set_prec(ent_scratch_bigfr,
285                        max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
286         bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
287         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
288 }
289 static Lisp_Object
290 ent_sum_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
291 {
292         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
293         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
294         bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
295         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
296 }
297 static Lisp_Object
298 ent_sum_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
299 {
300         return ent_sum_BIGFR_T_INT_T(r, l);
301 }
302 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
303 static Lisp_Object
304 ent_sum_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
305 {
306         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
307         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
308         bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
309         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
310 }
311 static Lisp_Object
312 ent_sum_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
313 {
314         return ent_sum_BIGFR_T_BIGZ_T(r, l);
315 }
316 #endif
317 #if defined HAVE_MPQ && defined WITH_GMP
318 static Lisp_Object
319 ent_sum_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
320 {
321         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
322         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
323         bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
324         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
325 }
326 static Lisp_Object
327 ent_sum_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
328 {
329         return ent_sum_BIGFR_T_BIGQ_T(r, l);
330 }
331 #endif
332 #if defined HAVE_MPF && defined WITH_GMP
333 static Lisp_Object
334 ent_sum_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
335 {
336         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
337         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
338         bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
339         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
340 }
341 static Lisp_Object
342 ent_sum_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
343 {
344         return ent_sum_BIGFR_T_BIGF_T(r, l);
345 }
346 #endif
347 #ifdef HAVE_FPFLOAT
348 static Lisp_Object
349 ent_sum_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
350 {
351         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
352         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
353         bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
354         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
355 }
356 static Lisp_Object
357 ent_sum_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
358 {
359         return ent_sum_BIGFR_T_FLOAT_T(r, l);
360 }
361 #endif
362
363
364 static Lisp_Object
365 ent_diff_BIGFR_T(Lisp_Object l, Lisp_Object r)
366 {
367         bigfr_set_prec(ent_scratch_bigfr,
368                        max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
369         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
370         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
371 }
372 static Lisp_Object
373 ent_diff_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
374 {
375         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
376         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
377         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
378         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
379 }
380 static Lisp_Object
381 ent_diff_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
382 {
383         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
384         bigfr_set_long(ent_scratch_bigfr, ent_int(l));
385         bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
386         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
387 }
388 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
389 static Lisp_Object
390 ent_diff_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
391 {
392         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
393         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
394         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
395         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
396 }
397 static Lisp_Object
398 ent_diff_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
399 {
400         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
401         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
402         bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
403         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
404 }
405 #endif
406 #if defined HAVE_MPQ && defined WITH_GMP
407 static Lisp_Object
408 ent_diff_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
409 {
410         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
411         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
412         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
413         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
414 }
415 static Lisp_Object
416 ent_diff_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
417 {
418         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
419         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
420         bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
421         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
422 }
423 #endif
424 #if defined HAVE_MPF && defined WITH_GMP
425 static Lisp_Object
426 ent_diff_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
427 {
428         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
429         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
430         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
431         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
432 }
433 static Lisp_Object
434 ent_diff_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
435 {
436         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
437         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
438         bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
439         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
440 }
441 #endif
442 #ifdef HAVE_FPFLOAT
443 static Lisp_Object
444 ent_diff_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
445 {
446         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
447         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
448         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
449         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
450 }
451 static Lisp_Object
452 ent_diff_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
453 {
454         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
455         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
456         bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
457         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
458 }
459 #endif
460
461 static Lisp_Object
462 ent_neg_BIGFR_T(Lisp_Object l)
463 {
464         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
465         bigfr_neg(ent_scratch_bigfr, XBIGFR_DATA(l));
466         return make_bigfr_bfr(ent_scratch_bigfr);
467 }
468
469 static Lisp_Object
470 ent_prod_BIGFR_T(Lisp_Object l, Lisp_Object r)
471 {
472         bigfr_set_prec(ent_scratch_bigfr,
473                        max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
474         bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
475         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
476 }
477 static Lisp_Object
478 ent_prod_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
479 {
480         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
481         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
482         bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
483         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
484 }
485 static Lisp_Object
486 ent_prod_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
487 {
488         return ent_prod_BIGFR_T_INT_T(r, l);
489 }
490 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
491 static Lisp_Object
492 ent_prod_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
493 {
494         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
495         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
496         bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
497         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
498 }
499 static Lisp_Object
500 ent_prod_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
501 {
502         return ent_prod_BIGFR_T_BIGZ_T(r, l);
503 }
504 #endif
505 #if defined HAVE_MPQ && defined WITH_GMP
506 static Lisp_Object
507 ent_prod_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
508 {
509         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
510         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
511         bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
512         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
513 }
514 static Lisp_Object
515 ent_prod_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
516 {
517         return ent_prod_BIGFR_T_BIGQ_T(r, l);
518 }
519 #endif
520 #if defined HAVE_MPF && defined WITH_GMP
521 static Lisp_Object
522 ent_prod_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
523 {
524         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
525         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
526         bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
527         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
528 }
529 static Lisp_Object
530 ent_prod_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
531 {
532         return ent_prod_BIGFR_T_BIGF_T(r, l);
533 }
534 #endif
535 #ifdef HAVE_FPFLOAT
536 static Lisp_Object
537 ent_prod_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
538 {
539         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
540         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
541         bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
542         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
543 }
544 static Lisp_Object
545 ent_prod_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
546 {
547         return ent_prod_BIGFR_T_FLOAT_T(r, l);
548 }
549 #endif
550
551 static Lisp_Object
552 ent_div_BIGFR_T(Lisp_Object l, Lisp_Object r)
553 {
554         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
555                 int lsgn = bigfr_sign(XBIGFR_DATA(l));
556                 if (lsgn > 0)
557                         return make_indef(POS_INFINITY);
558                 else if (lsgn < 0)
559                         return make_indef(NEG_INFINITY);
560                 else
561                         return make_indef(NOT_A_NUMBER);
562         }
563         bigfr_set_prec(ent_scratch_bigfr,
564                       max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
565         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
566         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
567 }
568 static Lisp_Object
569 ent_div_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
570 {
571         if (ent_int(r) == 0) {
572                 int lsgn = bigfr_sign(XBIGFR_DATA(l));
573                 if (lsgn > 0)
574                         return make_indef(POS_INFINITY);
575                 else if (lsgn < 0)
576                         return make_indef(NEG_INFINITY);
577                 else
578                         return make_indef(NOT_A_NUMBER);
579         }
580
581         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
582         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
583         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
584         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
585 }
586 static Lisp_Object
587 ent_div_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
588 {
589         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
590                 EMACS_INT rl = ent_int(l);
591                 if (rl > 0)
592                         return make_indef(POS_INFINITY);
593                 else if (rl < 0)
594                         return make_indef(NEG_INFINITY);
595                 else
596                         return make_indef(NOT_A_NUMBER);
597         }
598
599         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
600         bigfr_set_long(ent_scratch_bigfr, ent_int(l));
601         bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
602         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
603 }
604 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
605 static Lisp_Object
606 ent_div_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
607 {
608         if (bigz_sign(XBIGZ_DATA(r)) == 0) {
609                 int lsgn = bigfr_sign(XBIGFR_DATA(l));
610                 if (lsgn > 0)
611                         return make_indef(POS_INFINITY);
612                 else if (lsgn < 0)
613                         return make_indef(NEG_INFINITY);
614                 else
615                         return make_indef(NOT_A_NUMBER);
616         }
617
618         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
619         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
620         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
621         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
622 }
623 static Lisp_Object
624 ent_div_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
625 {
626         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
627                 int lsgn = bigz_sign(XBIGZ_DATA(l));
628                 if (lsgn > 0)
629                         return make_indef(POS_INFINITY);
630                 else if (lsgn < 0)
631                         return make_indef(NEG_INFINITY);
632                 else
633                         return make_indef(NOT_A_NUMBER);
634         }
635
636         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
637         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
638         bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
639         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
640 }
641 #endif
642 #if defined HAVE_MPQ && defined WITH_GMP
643 static Lisp_Object
644 ent_div_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
645 {
646         if (bigq_sign(XBIGQ_DATA(r)) == 0) {
647                 int lsgn = bigfr_sign(XBIGFR_DATA(l));
648                 if (lsgn > 0)
649                         return make_indef(POS_INFINITY);
650                 else if (lsgn < 0)
651                         return make_indef(NEG_INFINITY);
652                 else
653                         return make_indef(NOT_A_NUMBER);
654         }
655
656         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
657         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
658         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
659         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
660 }
661 static Lisp_Object
662 ent_div_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
663 {
664         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
665                 int lsgn = bigq_sign(XBIGQ_DATA(l));
666                 if (lsgn > 0)
667                         return make_indef(POS_INFINITY);
668                 else if (lsgn < 0)
669                         return make_indef(NEG_INFINITY);
670                 else
671                         return make_indef(NOT_A_NUMBER);
672         }
673
674         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
675         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
676         bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
677         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
678 }
679 #endif
680 #if defined HAVE_MPF && defined WITH_GMP
681 static Lisp_Object
682 ent_div_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
683 {
684         if (bigf_sign(XBIGF_DATA(r)) == 0) {
685                 int lsgn = bigfr_sign(XBIGFR_DATA(l));
686                 if (lsgn > 0)
687                         return make_indef(POS_INFINITY);
688                 else if (lsgn < 0)
689                         return make_indef(NEG_INFINITY);
690                 else
691                         return make_indef(NOT_A_NUMBER);
692         }
693
694         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
695         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
696         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
697         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
698 }
699 static Lisp_Object
700 ent_div_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
701 {
702         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
703                 int lsgn = bigf_sign(XBIGF_DATA(l));
704                 if (lsgn > 0)
705                         return make_indef(POS_INFINITY);
706                 else if (lsgn < 0)
707                         return make_indef(NEG_INFINITY);
708                 else
709                         return make_indef(NOT_A_NUMBER);
710         }
711
712         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
713         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
714         bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
715         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
716 }
717 #endif
718 #ifdef HAVE_FPFLOAT
719 static Lisp_Object
720 ent_div_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
721 {
722         if (XFLOAT_DATA(r) == 0.0f) {
723                 int lsgn = bigfr_sign(XBIGFR_DATA(l));
724                 if (lsgn > 0)
725                         return make_indef(POS_INFINITY);
726                 else if (lsgn < 0)
727                         return make_indef(NEG_INFINITY);
728                 else
729                         return make_indef(NOT_A_NUMBER);
730         }
731
732         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
733         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
734         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
735         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
736 }
737 static Lisp_Object
738 ent_div_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
739 {
740         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
741                 if (XFLOAT_DATA(l) > 0.0f)
742                         return make_indef(POS_INFINITY);
743                 else if (XFLOAT_DATA(r) < 0.0f)
744                         return make_indef(NEG_INFINITY);
745                 else
746                         return make_indef(NOT_A_NUMBER);
747         }
748
749         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
750         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
751         bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
752         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
753 }
754 #endif
755
756 static Lisp_Object
757 ent_inv_BIGFR_T(Lisp_Object r)
758 {
759         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
760                 return make_indef(POS_INFINITY);
761         }
762         bigfr_set_long(ent_scratch_bigfr, 1L);
763         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
764         bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
765         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
766 }
767 static Lisp_Object
768 ent_rem_BIGFR_T(Lisp_Object unused, Lisp_Object r)
769 {
770         return Qent_mpfr_zero;
771 }
772 static Lisp_Object
773 ent_mod_BIGFR_T(Lisp_Object l, Lisp_Object r)
774 {
775         if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
776                 return Qent_mpfr_zero;
777         }
778         bigfr_set_prec(ent_scratch_bigfr,
779                        max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
780         bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
781         bigfr_trunc(ent_scratch_bigfr, ent_scratch_bigfr);
782         bigfr_mul(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
783         bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
784         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
785 }
786 #ifdef bigfr_pow
787 static Lisp_Object
788 ent_pow_BIGFR_T_integer(Lisp_Object l, Lisp_Object r)
789 {
790         EMACS_INT expo = 0;
791
792         if (NILP(Fnonnegativep(r))) {
793                 return ent_unop_inv(
794                         ent_pow_BIGFR_T_integer(l, ent_unop_neg(r)));
795         }
796
797         if (INTP(r)) {
798                 expo = ent_int(r);
799 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
800         } else if (BIGZP(r)) {
801                 if (bigz_fits_long_p(XBIGZ_DATA(r)))
802                         expo = bigz_to_long(XBIGZ_DATA(r));
803                 else
804                         Fsignal(Qarith_error, list1(r));
805 #endif
806         } else {
807                 Fsignal(Qarith_error, list1(r));
808                 return Qnil;
809         }
810
811         bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
812         bigfr_pow(ent_scratch_bigfr, XBIGFR_DATA(l), expo);
813         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
814 }
815 #endif
816
817 /* relations */
818 static inline int
819 ent_lt_bigfr(Lisp_Object l, Lisp_Object r)
820 {
821         return (bigfr_lt(XBIGFR_DATA(l), XBIGFR_DATA(r)));
822 }
823 static inline int
824 ent_lt_bigfr_int(Lisp_Object l, Lisp_Object r)
825 {
826         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
827         return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
828 }
829 static inline int
830 ent_lt_int_bigfr(Lisp_Object l, Lisp_Object r)
831 {
832         bigfr_set_long(ent_scratch_bigfr, ent_int(l));
833         return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
834 }
835 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
836 static inline int
837 ent_lt_bigfr_bigz(Lisp_Object l, Lisp_Object r)
838 {
839         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
840         return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
841 }
842 static inline int
843 ent_lt_bigz_bigfr(Lisp_Object l, Lisp_Object r)
844 {
845         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
846         return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
847 }
848 #endif
849 #if defined HAVE_MPQ && defined WITH_GMP
850 static inline int
851 ent_lt_bigfr_bigq(Lisp_Object l, Lisp_Object r)
852 {
853         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
854         return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
855 }
856 static inline int
857 ent_lt_bigq_bigfr(Lisp_Object l, Lisp_Object r)
858 {
859         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
860         return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
861 }
862 #endif
863 #if defined HAVE_MPF && defined WITH_GMP
864 static inline int
865 ent_lt_bigfr_bigf(Lisp_Object l, Lisp_Object r)
866 {
867         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
868         return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
869 }
870 static inline int
871 ent_lt_bigf_bigfr(Lisp_Object l, Lisp_Object r)
872 {
873         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
874         return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
875 }
876 #endif
877 #ifdef HAVE_FPFLOAT
878 static inline int
879 ent_lt_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
880 {
881         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
882         return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
883 }
884 static inline int
885 ent_lt_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
886 {
887         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
888         return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
889 }
890 #endif
891
892 static inline int
893 ent_gt_bigfr(Lisp_Object l, Lisp_Object r)
894 {
895         return (bigfr_gt(XBIGFR_DATA(l), XBIGFR_DATA(r)));
896 }
897 static inline int
898 ent_gt_bigfr_int(Lisp_Object l, Lisp_Object r)
899 {
900         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
901         return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
902 }
903 static inline int
904 ent_gt_int_bigfr(Lisp_Object l, Lisp_Object r)
905 {
906         bigfr_set_long(ent_scratch_bigfr, ent_int(l));
907         return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
908 }
909 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
910 static inline int
911 ent_gt_bigfr_bigz(Lisp_Object l, Lisp_Object r)
912 {
913         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
914         return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
915 }
916 static inline int
917 ent_gt_bigz_bigfr(Lisp_Object l, Lisp_Object r)
918 {
919         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
920         return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
921 }
922 #endif
923 #if defined HAVE_MPQ && defined WITH_GMP
924 static inline int
925 ent_gt_bigfr_bigq(Lisp_Object l, Lisp_Object r)
926 {
927         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
928         return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
929 }
930 static inline int
931 ent_gt_bigq_bigfr(Lisp_Object l, Lisp_Object r)
932 {
933         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
934         return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
935 }
936 #endif
937 #if defined HAVE_MPF && defined WITH_GMP
938 static inline int
939 ent_gt_bigfr_bigf(Lisp_Object l, Lisp_Object r)
940 {
941         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
942         return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
943 }
944 static inline int
945 ent_gt_bigf_bigfr(Lisp_Object l, Lisp_Object r)
946 {
947         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
948         return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
949 }
950 #endif
951 #ifdef HAVE_FPFLOAT
952 static inline int
953 ent_gt_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
954 {
955         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
956         return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
957 }
958 static inline int
959 ent_gt_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
960 {
961         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
962         return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
963 }
964 #endif
965
966 static inline int
967 ent_eq_bigfr(Lisp_Object l, Lisp_Object r)
968 {
969         return (bigfr_eq(XBIGFR_DATA(l), XBIGFR_DATA(r)));
970 }
971 static inline int
972 ent_eq_bigfr_int(Lisp_Object l, Lisp_Object r)
973 {
974         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
975         return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
976 }
977 static inline int
978 ent_eq_int_bigfr(Lisp_Object l, Lisp_Object r)
979 {
980         bigfr_set_long(ent_scratch_bigfr, ent_int(l));
981         return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
982 }
983 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
984 static inline int
985 ent_eq_bigfr_bigz(Lisp_Object l, Lisp_Object r)
986 {
987         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
988         return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
989 }
990 static inline int
991 ent_eq_bigz_bigfr(Lisp_Object l, Lisp_Object r)
992 {
993         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
994         return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
995 }
996 #endif
997 #if defined HAVE_MPQ && defined WITH_GMP
998 static inline int
999 ent_eq_bigfr_bigq(Lisp_Object l, Lisp_Object r)
1000 {
1001         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
1002         return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1003 }
1004 static inline int
1005 ent_eq_bigq_bigfr(Lisp_Object l, Lisp_Object r)
1006 {
1007         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
1008         return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1009 }
1010 #endif
1011 #if defined HAVE_MPF && defined WITH_GMP
1012 static inline int
1013 ent_eq_bigfr_bigf(Lisp_Object l, Lisp_Object r)
1014 {
1015         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
1016         return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1017 }
1018 static inline int
1019 ent_eq_bigf_bigfr(Lisp_Object l, Lisp_Object r)
1020 {
1021         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
1022         return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1023 }
1024 #endif
1025 #ifdef HAVE_FPFLOAT
1026 static inline int
1027 ent_eq_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
1028 {
1029         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
1030         return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1031 }
1032 static inline int
1033 ent_eq_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
1034 {
1035         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
1036         return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1037 }
1038 #endif
1039
1040 static inline int
1041 ent_ne_bigfr(Lisp_Object l, Lisp_Object r)
1042 {
1043         return !(bigfr_eq(XBIGFR_DATA(l), XBIGFR_DATA(r)));
1044 }
1045 static inline int
1046 ent_ne_bigfr_int(Lisp_Object l, Lisp_Object r)
1047 {
1048         bigfr_set_long(ent_scratch_bigfr, ent_int(r));
1049         return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1050 }
1051 static inline int
1052 ent_ne_int_bigfr(Lisp_Object l, Lisp_Object r)
1053 {
1054         bigfr_set_long(ent_scratch_bigfr, ent_int(l));
1055         return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1056 }
1057 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1058 static inline int
1059 ent_ne_bigfr_bigz(Lisp_Object l, Lisp_Object r)
1060 {
1061         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
1062         return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1063 }
1064 static inline int
1065 ent_ne_bigz_bigfr(Lisp_Object l, Lisp_Object r)
1066 {
1067         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
1068         return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1069 }
1070 #endif
1071 #if defined HAVE_MPQ && defined WITH_GMP
1072 static inline int
1073 ent_ne_bigfr_bigq(Lisp_Object l, Lisp_Object r)
1074 {
1075         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
1076         return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1077 }
1078 static inline int
1079 ent_ne_bigq_bigfr(Lisp_Object l, Lisp_Object r)
1080 {
1081         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
1082         return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1083 }
1084 #endif
1085 #if defined HAVE_MPF && defined WITH_GMP
1086 static inline int
1087 ent_ne_bigfr_bigf(Lisp_Object l, Lisp_Object r)
1088 {
1089         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
1090         return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1091 }
1092 static inline int
1093 ent_ne_bigf_bigfr(Lisp_Object l, Lisp_Object r)
1094 {
1095         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
1096         return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1097 }
1098 #endif
1099 #ifdef HAVE_FPFLOAT
1100 static inline int
1101 ent_ne_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
1102 {
1103         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
1104         return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1105 }
1106 static inline int
1107 ent_ne_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
1108 {
1109         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
1110         return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1111 }
1112 #endif
1113
1114 \f
1115 static inline Lisp_Object
1116 _ent_lift_INT_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1117 {
1118         unsigned long precision = la->precision;
1119         return make_bigfr(ent_int(number), precision);
1120 }
1121
1122 static inline Lisp_Object
1123 _ent_lift_BIGFR_T_INT_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
1124 {
1125         return make_int(bigfr_to_long(XBIGFR_DATA(number)));
1126 }
1127
1128 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1129 static inline Lisp_Object
1130 _ent_lift_BIGZ_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1131 {
1132         unsigned long precision = la->precision;
1133
1134         bigfr_set_prec(ent_scratch_bigfr, precision);
1135         bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(number));
1136         return make_bigfr_bfr(ent_scratch_bigfr);
1137 }
1138
1139 static inline Lisp_Object
1140 _ent_lift_BIGFR_T_BIGZ_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
1141 {
1142         bigz_set_bigfr(ent_scratch_bigz, XBIGFR_DATA(number));
1143         return make_bigz_bz(ent_scratch_bigz);
1144 }
1145 #endif  /* HAVE_MPZ */
1146
1147 #if defined HAVE_MPQ && defined WITH_GMP
1148 static inline Lisp_Object
1149 _ent_lift_BIGQ_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1150 {
1151         unsigned long precision = la->precision;
1152
1153         bigfr_set_prec(ent_scratch_bigfr, precision);
1154         bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(number));
1155         return make_bigfr_bfr(ent_scratch_bigfr);
1156 }
1157 #endif  /* HAVE_MPQ */
1158
1159 #if defined HAVE_MPF && defined WITH_GMP
1160 static inline Lisp_Object
1161 _ent_lift_BIGF_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1162 {
1163         unsigned long precision = la->precision;
1164
1165         bigfr_set_prec(ent_scratch_bigfr, precision);
1166         bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(number));
1167         return make_bigfr_bfr(ent_scratch_bigfr);
1168 }
1169
1170 static inline Lisp_Object
1171 _ent_lift_BIGFR_T_BIGF_T(Lisp_Object number, ent_lift_args_t la)
1172 {
1173         unsigned long precision = la->precision;
1174
1175         bigf_set_prec(ent_scratch_bigf, precision);
1176         bigf_set_bigfr(ent_scratch_bigf, XBIGFR_DATA(number));
1177         return make_bigf_bf(ent_scratch_bigf);
1178 }
1179 #endif  /* HAVE_MPF */
1180
1181 #ifdef HAVE_FPFLOAT
1182 static inline Lisp_Object
1183 _ent_lift_FLOAT_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1184 {
1185         unsigned long precision = la->precision;
1186
1187         bigfr_set_prec(ent_scratch_bigfr, precision);
1188         bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(number));
1189         return make_bigfr_bfr(ent_scratch_bigfr);
1190 }
1191
1192 static inline Lisp_Object
1193 _ent_lift_BIGFR_T_FLOAT_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
1194 {
1195         return make_float(bigfr_to_fpfloat(XBIGFR_DATA(number)));
1196 }
1197 #endif
1198
1199 static inline Lisp_Object
1200 _ent_lift_BIGFR_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1201 {
1202         unsigned long precision = la->precision;
1203
1204         bigfr_set_prec(ent_scratch_bigfr, precision);
1205         bigfr_set(ent_scratch_bigfr, XBIGFR_DATA(number));
1206         return ent_mpfr_wipe_indef(ent_scratch_bigfr);
1207 }
1208
1209 static inline int
1210 ent_mpfr_zerop(Lisp_Object l)
1211 {
1212         return (bigfr_sign(XBIGFR_DATA(l)) == 0);
1213 }
1214
1215 static inline int
1216 ent_mpfr_onep(Lisp_Object l)
1217 {
1218         return (bigfr_to_fpfloat(XBIGFR_DATA(l)) == 1.0f);
1219 }
1220
1221 static inline int
1222 ent_mpfr_unitp(Lisp_Object unused)
1223 {
1224         return 1;
1225 }
1226
1227 \f
1228 static inline void
1229 ent_mpfr_nullary_optable_init(void)
1230 {
1231         Qent_mpfr_zero = make_bigfr(0.0f, internal_get_precision(Qnil));
1232         Qent_mpfr_one = make_bigfr(1.0f, internal_get_precision(Qnil));
1233         staticpro(&Qent_mpfr_zero);
1234         staticpro(&Qent_mpfr_one);
1235
1236         ent_nullop_register(ASE_NULLARY_OP_ZERO, BIGFR_T, Qent_mpfr_zero);
1237         ent_nullop_register(ASE_NULLARY_OP_ONE, BIGFR_T, Qent_mpfr_one);
1238 }
1239
1240 static inline void
1241 ent_mpfr_unary_optable_init(void)
1242 {
1243         ent_unop_register(ASE_UNARY_OP_NEG, BIGFR_T, ent_neg_BIGFR_T);
1244         ent_unop_register(ASE_UNARY_OP_INV, BIGFR_T, ent_inv_BIGFR_T);
1245 }
1246
1247 static inline void
1248 ent_mpfr_binary_optable_init(void)
1249 {
1250         /* sums */
1251         ent_binop_register(ASE_BINARY_OP_SUM,
1252                            BIGFR_T, BIGFR_T, ent_sum_BIGFR_T);
1253         ent_binop_register(ASE_BINARY_OP_SUM,
1254                            BIGFR_T, INT_T, ent_sum_BIGFR_T_INT_T);
1255         ent_binop_register(ASE_BINARY_OP_SUM,
1256                            INT_T, BIGFR_T, ent_sum_INT_T_BIGFR_T);
1257 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1258         ent_binop_register(ASE_BINARY_OP_SUM,
1259                            BIGFR_T, BIGZ_T, ent_sum_BIGFR_T_BIGZ_T);
1260         ent_binop_register(ASE_BINARY_OP_SUM,
1261                            BIGZ_T, BIGFR_T, ent_sum_BIGZ_T_BIGFR_T);
1262 #endif
1263 #if defined HAVE_MPQ && defined WITH_GMP
1264         ent_binop_register(ASE_BINARY_OP_SUM,
1265                            BIGFR_T, BIGQ_T, ent_sum_BIGFR_T_BIGQ_T);
1266         ent_binop_register(ASE_BINARY_OP_SUM,
1267                            BIGQ_T, BIGFR_T, ent_sum_BIGQ_T_BIGFR_T);
1268 #endif
1269 #if defined HAVE_MPF && defined WITH_GMP
1270         ent_binop_register(ASE_BINARY_OP_SUM,
1271                            BIGFR_T, BIGF_T, ent_sum_BIGFR_T_BIGF_T);
1272         ent_binop_register(ASE_BINARY_OP_SUM,
1273                            BIGF_T, BIGFR_T, ent_sum_BIGF_T_BIGFR_T);
1274 #endif
1275 #ifdef HAVE_FPFLOAT
1276         ent_binop_register(ASE_BINARY_OP_SUM,
1277                            FLOAT_T, BIGFR_T, ent_sum_FLOAT_T_BIGFR_T);
1278         ent_binop_register(ASE_BINARY_OP_SUM,
1279                            BIGFR_T, FLOAT_T, ent_sum_BIGFR_T_FLOAT_T);
1280 #endif
1281
1282         ent_binop_register(ASE_BINARY_OP_DIFF,
1283                            BIGFR_T, BIGFR_T, ent_diff_BIGFR_T);
1284         ent_binop_register(ASE_BINARY_OP_DIFF,
1285                            BIGFR_T, INT_T, ent_diff_BIGFR_T_INT_T);
1286         ent_binop_register(ASE_BINARY_OP_DIFF,
1287                            INT_T, BIGFR_T, ent_diff_INT_T_BIGFR_T);
1288 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1289         ent_binop_register(ASE_BINARY_OP_DIFF,
1290                            BIGFR_T, BIGZ_T, ent_diff_BIGFR_T_BIGZ_T);
1291         ent_binop_register(ASE_BINARY_OP_DIFF,
1292                            BIGZ_T, BIGFR_T, ent_diff_BIGZ_T_BIGFR_T);
1293 #endif
1294 #if defined HAVE_MPQ && defined WITH_GMP
1295         ent_binop_register(ASE_BINARY_OP_DIFF,
1296                            BIGFR_T, BIGQ_T, ent_diff_BIGFR_T_BIGQ_T);
1297         ent_binop_register(ASE_BINARY_OP_DIFF,
1298                            BIGQ_T, BIGFR_T, ent_diff_BIGQ_T_BIGFR_T);
1299 #endif
1300 #if defined HAVE_MPF && defined WITH_GMP
1301         ent_binop_register(ASE_BINARY_OP_DIFF,
1302                            BIGFR_T, BIGF_T, ent_diff_BIGFR_T_BIGF_T);
1303         ent_binop_register(ASE_BINARY_OP_DIFF,
1304                            BIGF_T, BIGFR_T, ent_diff_BIGF_T_BIGFR_T);
1305 #endif
1306 #ifdef HAVE_FPFLOAT
1307         ent_binop_register(ASE_BINARY_OP_DIFF,
1308                            FLOAT_T, BIGFR_T, ent_diff_FLOAT_T_BIGFR_T);
1309         ent_binop_register(ASE_BINARY_OP_DIFF,
1310                            BIGFR_T, FLOAT_T, ent_diff_BIGFR_T_FLOAT_T);
1311 #endif
1312
1313         /* products */
1314         ent_binop_register(ASE_BINARY_OP_PROD,
1315                            BIGFR_T, BIGFR_T, ent_prod_BIGFR_T);
1316         ent_binop_register(ASE_BINARY_OP_PROD,
1317                            BIGFR_T, INT_T, ent_prod_BIGFR_T_INT_T);
1318         ent_binop_register(ASE_BINARY_OP_PROD,
1319                            INT_T, BIGFR_T, ent_prod_INT_T_BIGFR_T);
1320 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1321         ent_binop_register(ASE_BINARY_OP_PROD,
1322                            BIGFR_T, BIGZ_T, ent_prod_BIGFR_T_BIGZ_T);
1323         ent_binop_register(ASE_BINARY_OP_PROD,
1324                            BIGZ_T, BIGFR_T, ent_prod_BIGZ_T_BIGFR_T);
1325 #endif
1326 #if defined HAVE_MPQ && defined WITH_GMP
1327         ent_binop_register(ASE_BINARY_OP_PROD,
1328                            BIGFR_T, BIGQ_T, ent_prod_BIGFR_T_BIGQ_T);
1329         ent_binop_register(ASE_BINARY_OP_PROD,
1330                            BIGQ_T, BIGFR_T, ent_prod_BIGQ_T_BIGFR_T);
1331 #endif
1332 #if defined HAVE_MPF && defined WITH_GMP
1333         ent_binop_register(ASE_BINARY_OP_PROD,
1334                            BIGFR_T, BIGF_T, ent_prod_BIGFR_T_BIGF_T);
1335         ent_binop_register(ASE_BINARY_OP_PROD,
1336                            BIGF_T, BIGFR_T, ent_prod_BIGF_T_BIGFR_T);
1337 #endif
1338 #ifdef HAVE_FPFLOAT
1339         ent_binop_register(ASE_BINARY_OP_PROD,
1340                            FLOAT_T, BIGFR_T, ent_prod_FLOAT_T_BIGFR_T);
1341         ent_binop_register(ASE_BINARY_OP_PROD,
1342                            BIGFR_T, FLOAT_T, ent_prod_BIGFR_T_FLOAT_T);
1343 #endif
1344
1345         ent_binop_register(ASE_BINARY_OP_DIV,
1346                            BIGFR_T, BIGFR_T, ent_div_BIGFR_T);
1347         ent_binop_register(ASE_BINARY_OP_DIV,
1348                            BIGFR_T, INT_T, ent_div_BIGFR_T_INT_T);
1349         ent_binop_register(ASE_BINARY_OP_DIV,
1350                            INT_T, BIGFR_T, ent_div_INT_T_BIGFR_T);
1351 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1352         ent_binop_register(ASE_BINARY_OP_DIV,
1353                            BIGFR_T, BIGZ_T, ent_div_BIGFR_T_BIGZ_T);
1354         ent_binop_register(ASE_BINARY_OP_DIV,
1355                            BIGZ_T, BIGFR_T, ent_div_BIGZ_T_BIGFR_T);
1356 #endif
1357 #if defined HAVE_MPQ && defined WITH_GMP
1358         ent_binop_register(ASE_BINARY_OP_DIV,
1359                            BIGFR_T, BIGQ_T, ent_div_BIGFR_T_BIGQ_T);
1360         ent_binop_register(ASE_BINARY_OP_DIV,
1361                            BIGQ_T, BIGFR_T, ent_div_BIGQ_T_BIGFR_T);
1362 #endif
1363 #if defined HAVE_MPF && defined WITH_GMP
1364         ent_binop_register(ASE_BINARY_OP_DIV,
1365                            BIGFR_T, BIGF_T, ent_div_BIGFR_T_BIGF_T);
1366         ent_binop_register(ASE_BINARY_OP_DIV,
1367                            BIGF_T, BIGFR_T, ent_div_BIGF_T_BIGFR_T);
1368 #endif
1369 #ifdef HAVE_FPFLOAT
1370         ent_binop_register(ASE_BINARY_OP_DIV,
1371                            FLOAT_T, BIGFR_T, ent_div_FLOAT_T_BIGFR_T);
1372         ent_binop_register(ASE_BINARY_OP_DIV,
1373                            BIGFR_T, FLOAT_T, ent_div_BIGFR_T_FLOAT_T);
1374 #endif
1375
1376         ent_binop_register(ASE_BINARY_OP_QUO,
1377                            BIGFR_T, BIGFR_T, ent_div_BIGFR_T);
1378         ent_binop_register(ASE_BINARY_OP_QUO,
1379                            BIGFR_T, INT_T, ent_div_BIGFR_T_INT_T);
1380         ent_binop_register(ASE_BINARY_OP_QUO,
1381                            INT_T, BIGFR_T, ent_div_INT_T_BIGFR_T);
1382 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1383         ent_binop_register(ASE_BINARY_OP_QUO,
1384                            BIGFR_T, BIGZ_T, ent_div_BIGFR_T_BIGZ_T);
1385         ent_binop_register(ASE_BINARY_OP_QUO,
1386                            BIGZ_T, BIGFR_T, ent_div_BIGZ_T_BIGFR_T);
1387 #endif
1388 #if defined HAVE_MPQ && defined WITH_GMP
1389         ent_binop_register(ASE_BINARY_OP_QUO,
1390                            BIGFR_T, BIGQ_T, ent_div_BIGFR_T_BIGQ_T);
1391         ent_binop_register(ASE_BINARY_OP_QUO,
1392                            BIGQ_T, BIGFR_T, ent_div_BIGQ_T_BIGFR_T);
1393 #endif
1394 #if defined HAVE_MPF && defined WITH_GMP
1395         ent_binop_register(ASE_BINARY_OP_QUO,
1396                            BIGFR_T, BIGF_T, ent_div_BIGFR_T_BIGF_T);
1397         ent_binop_register(ASE_BINARY_OP_QUO,
1398                            BIGF_T, BIGFR_T, ent_div_BIGF_T_BIGFR_T);
1399 #endif
1400 #ifdef HAVE_FPFLOAT
1401         ent_binop_register(ASE_BINARY_OP_QUO,
1402                            FLOAT_T, BIGFR_T, ent_div_FLOAT_T_BIGFR_T);
1403         ent_binop_register(ASE_BINARY_OP_QUO,
1404                            BIGFR_T, FLOAT_T, ent_div_BIGFR_T_FLOAT_T);
1405 #endif
1406
1407         /* remainders */
1408         ent_binop_register(ASE_BINARY_OP_MOD,
1409                            BIGFR_T, BIGFR_T, ent_mod_BIGFR_T);
1410         ent_binop_register(ASE_BINARY_OP_REM,
1411                            BIGFR_T, BIGFR_T, ent_rem_BIGFR_T);
1412         ent_binop_register(ASE_BINARY_OP_REM,
1413                            INT_T, BIGFR_T, ent_rem_BIGFR_T);
1414         ent_binop_register(ASE_BINARY_OP_REM,
1415                            INDEF_T, BIGFR_T, ent_rem_BIGFR_T);
1416 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1417         ent_binop_register(ASE_BINARY_OP_REM,
1418                            BIGZ_T, BIGFR_T, ent_rem_BIGFR_T);
1419 #endif
1420 #if defined HAVE_MPQ && defined WITH_GMP
1421         ent_binop_register(ASE_BINARY_OP_REM,
1422                            BIGQ_T, BIGFR_T, ent_rem_BIGFR_T);
1423 #endif
1424 #if defined HAVE_MPF && defined WITH_GMP
1425         ent_binop_register(ASE_BINARY_OP_REM,
1426                            BIGF_T, BIGFR_T, ent_rem_BIGFR_T);
1427 #endif
1428 #if HAVE_FPFLOAT
1429         ent_binop_register(ASE_BINARY_OP_REM,
1430                            FLOAT_T, BIGFR_T, ent_rem_BIGFR_T);
1431 #endif
1432
1433 #ifdef bigfr_pow
1434         ent_binop_register(ASE_BINARY_OP_POW,
1435                            BIGFR_T, INT_T, ent_pow_BIGFR_T_integer);
1436 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1437         ent_binop_register(ASE_BINARY_OP_POW,
1438                            BIGFR_T, BIGZ_T, ent_pow_BIGFR_T_integer);
1439 #endif
1440 #endif
1441 }
1442
1443 static inline void
1444 ent_mpfr_unary_reltable_init(void)
1445 {
1446         ent_unrel_register(ASE_UNARY_REL_ZEROP, BIGFR_T, ent_mpfr_zerop);
1447         ent_unrel_register(ASE_UNARY_REL_ONEP, BIGFR_T, ent_mpfr_onep);
1448         ent_unrel_register(ASE_UNARY_REL_UNITP, BIGFR_T, ent_mpfr_unitp);
1449 }
1450
1451 static inline void
1452 ent_mpfr_binary_reltable_init(void)
1453 {
1454         ent_binrel_register(ASE_BINARY_REL_LESSP,
1455                             BIGFR_T, BIGFR_T, ent_lt_bigfr);
1456         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1457                             BIGFR_T, BIGFR_T, ent_gt_bigfr);
1458         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1459                             BIGFR_T, BIGFR_T, ent_eq_bigfr);
1460         ent_binrel_register(ASE_BINARY_REL_NEQP,
1461                             BIGFR_T, BIGFR_T, ent_ne_bigfr);
1462
1463         ent_binrel_register(ASE_BINARY_REL_LESSP,
1464                             BIGFR_T, INT_T, ent_lt_bigfr_int);
1465         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1466                             BIGFR_T, INT_T, ent_gt_bigfr_int);
1467         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1468                             BIGFR_T, INT_T, ent_eq_bigfr_int);
1469         ent_binrel_register(ASE_BINARY_REL_NEQP,
1470                             BIGFR_T, INT_T, ent_ne_bigfr_int);
1471
1472         ent_binrel_register(ASE_BINARY_REL_LESSP,
1473                             INT_T, BIGFR_T, ent_lt_int_bigfr);
1474         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1475                             INT_T, BIGFR_T, ent_gt_int_bigfr);
1476         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1477                             INT_T, BIGFR_T, ent_eq_int_bigfr);
1478         ent_binrel_register(ASE_BINARY_REL_NEQP,
1479                             INT_T, BIGFR_T, ent_ne_int_bigfr);
1480
1481 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1482         ent_binrel_register(ASE_BINARY_REL_LESSP,
1483                             BIGFR_T, BIGZ_T, ent_lt_bigfr_bigz);
1484         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1485                             BIGFR_T, BIGZ_T, ent_gt_bigfr_bigz);
1486         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1487                             BIGFR_T, BIGZ_T, ent_eq_bigfr_bigz);
1488         ent_binrel_register(ASE_BINARY_REL_NEQP,
1489                             BIGFR_T, BIGZ_T, ent_ne_bigfr_bigz);
1490
1491         ent_binrel_register(ASE_BINARY_REL_LESSP,
1492                             BIGZ_T, BIGFR_T, ent_lt_bigz_bigfr);
1493         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1494                             BIGZ_T, BIGFR_T, ent_gt_bigz_bigfr);
1495         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1496                             BIGZ_T, BIGFR_T, ent_eq_bigz_bigfr);
1497         ent_binrel_register(ASE_BINARY_REL_NEQP,
1498                             BIGZ_T, BIGFR_T, ent_ne_bigz_bigfr);
1499 #endif
1500 #if defined HAVE_MPQ && defined WITH_GMP
1501         ent_binrel_register(ASE_BINARY_REL_LESSP,
1502                             BIGFR_T, BIGQ_T, ent_lt_bigfr_bigq);
1503         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1504                             BIGFR_T, BIGQ_T, ent_gt_bigfr_bigq);
1505         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1506                             BIGFR_T, BIGQ_T, ent_eq_bigfr_bigq);
1507         ent_binrel_register(ASE_BINARY_REL_NEQP,
1508                             BIGFR_T, BIGQ_T, ent_ne_bigfr_bigq);
1509
1510         ent_binrel_register(ASE_BINARY_REL_LESSP,
1511                             BIGQ_T, BIGFR_T, ent_lt_bigq_bigfr);
1512         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1513                             BIGQ_T, BIGFR_T, ent_gt_bigq_bigfr);
1514         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1515                             BIGQ_T, BIGFR_T, ent_eq_bigq_bigfr);
1516         ent_binrel_register(ASE_BINARY_REL_NEQP,
1517                             BIGQ_T, BIGFR_T, ent_ne_bigq_bigfr);
1518 #endif
1519 #if defined HAVE_MPF && defined WITH_GMP
1520         ent_binrel_register(ASE_BINARY_REL_LESSP,
1521                             BIGFR_T, BIGF_T, ent_lt_bigfr_bigf);
1522         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1523                             BIGFR_T, BIGF_T, ent_gt_bigfr_bigf);
1524         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1525                             BIGFR_T, BIGF_T, ent_eq_bigfr_bigf);
1526         ent_binrel_register(ASE_BINARY_REL_NEQP,
1527                             BIGFR_T, BIGF_T, ent_ne_bigfr_bigf);
1528
1529         ent_binrel_register(ASE_BINARY_REL_LESSP,
1530                             BIGF_T, BIGFR_T, ent_lt_bigf_bigfr);
1531         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1532                             BIGF_T, BIGFR_T, ent_gt_bigf_bigfr);
1533         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1534                             BIGF_T, BIGFR_T, ent_eq_bigf_bigfr);
1535         ent_binrel_register(ASE_BINARY_REL_NEQP,
1536                             BIGF_T, BIGFR_T, ent_ne_bigf_bigfr);
1537 #endif
1538 #ifdef HAVE_FPFLOAT
1539         ent_binrel_register(ASE_BINARY_REL_LESSP,
1540                             BIGFR_T, FLOAT_T, ent_lt_bigfr_fpfloat);
1541         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1542                             BIGFR_T, FLOAT_T, ent_gt_bigfr_fpfloat);
1543         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1544                             BIGFR_T, FLOAT_T, ent_eq_bigfr_fpfloat);
1545         ent_binrel_register(ASE_BINARY_REL_NEQP,
1546                             BIGFR_T, FLOAT_T, ent_ne_bigfr_fpfloat);
1547
1548         ent_binrel_register(ASE_BINARY_REL_LESSP,
1549                             FLOAT_T, BIGFR_T, ent_lt_fpfloat_bigfr);
1550         ent_binrel_register(ASE_BINARY_REL_GREATERP,
1551                             FLOAT_T, BIGFR_T, ent_gt_fpfloat_bigfr);
1552         ent_binrel_register(ASE_BINARY_REL_EQUALP,
1553                             FLOAT_T, BIGFR_T, ent_eq_fpfloat_bigfr);
1554         ent_binrel_register(ASE_BINARY_REL_NEQP,
1555                             FLOAT_T, BIGFR_T, ent_ne_fpfloat_bigfr);
1556 #endif
1557 }
1558
1559 static inline void
1560 ent_mpfr_lifttable_init(void)
1561 {
1562         ent_lift_register(BIGFR_T, BIGFR_T, _ent_lift_BIGFR_T_BIGFR_T);
1563         ent_lift_register(BIGFR_T, INT_T, _ent_lift_BIGFR_T_INT_T);
1564         ent_lift_register(INT_T, BIGFR_T, _ent_lift_INT_T_BIGFR_T);
1565 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1566         ent_lift_register(BIGFR_T, BIGZ_T, _ent_lift_BIGFR_T_BIGZ_T);
1567         ent_lift_register(BIGZ_T, BIGFR_T, _ent_lift_BIGZ_T_BIGFR_T);
1568 #endif
1569 #if defined HAVE_MPQ && defined WITH_GMP
1570         ent_lift_register(BIGQ_T, BIGFR_T, _ent_lift_BIGQ_T_BIGFR_T);
1571 #endif
1572 #if defined HAVE_MPF && defined WITH_GMP
1573         ent_lift_register(BIGFR_T, BIGF_T, _ent_lift_BIGFR_T_BIGF_T);
1574         ent_lift_register(BIGF_T, BIGFR_T, _ent_lift_BIGF_T_BIGFR_T);
1575 #endif
1576 #ifdef HAVE_FPFLOAT
1577         ent_lift_register(BIGFR_T, FLOAT_T, _ent_lift_BIGFR_T_FLOAT_T);
1578         ent_lift_register(FLOAT_T, BIGFR_T, _ent_lift_FLOAT_T_BIGFR_T);
1579 #endif
1580         ent_lift_register(INDEF_T, BIGFR_T, ent_lift_INDEF_T_COMPARABLE);
1581 }
1582
1583 \f
1584 void init_optables_BIGFR_T(void)
1585 {
1586         ent_mpfr_nullary_optable_init();
1587         ent_mpfr_unary_optable_init();
1588         ent_mpfr_binary_optable_init();
1589         ent_mpfr_unary_reltable_init();
1590         ent_mpfr_binary_reltable_init();
1591         ent_mpfr_lifttable_init();
1592 }
1593
1594 void init_ent_mpfr(void)
1595 {
1596         bigfr_init(ent_scratch_bigfr);
1597
1598         Veuler = make_bigfr(0.0, 2048UL);
1599         bigfr_set_long(ent_scratch_bigfr, 1L);
1600         mpfr_exp(XBIGFR_DATA(Veuler), ent_scratch_bigfr, GMP_RNDN);
1601
1602         Veuler_mascheroni = make_bigfr(0.0, 2048UL);
1603         mpfr_const_euler(XBIGFR_DATA(Veuler_mascheroni), GMP_RNDN);
1604
1605         Vpi = make_bigfr(0.0, 2048UL);
1606         mpfr_const_pi(XBIGFR_DATA(Vpi), GMP_RNDN);
1607 }
1608
1609 void syms_of_ent_mpfr(void)
1610 {
1611         INIT_LRECORD_IMPLEMENTATION(bigfr);
1612
1613         DEFSUBR(Fbigfr_get_precision);
1614         DEFSUBR(Fbigfr_set_precision);
1615
1616         bigfr_set_default_prec(128UL);
1617 }
1618
1619 void vars_of_ent_mpfr(void)
1620 {
1621         /* define pi and e */
1622
1623         /* just some dummy values atm, to make the dumper smile */
1624         Veuler = make_int(1L);
1625         Veuler_mascheroni = make_int(1L);
1626         Vpi = make_int(1L);
1627
1628         DEFVAR_CONST_LISP("euler", &Veuler /*
1629 The value of Euler's constant e (2.7182818...).
1630                                            */);
1631         DEFVAR_CONST_LISP("euler-mascheroni", &Veuler_mascheroni /*
1632 The value of the Euler-Mascheroni constant (0.5772156...).
1633                                                                  */);
1634         DEFVAR_CONST_LISP("pi", &Vpi /*
1635 The value of pi (3.1415926...).
1636                                      */);
1637
1638         Fprovide(intern("bigfr"));
1639 }