2 ent-mpfr.c -- 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/>. */
27 #include "sysproc.h" /* For qxe_getpid */
33 Lisp_Object Veuler_mascheroni;
36 bigfr ent_scratch_bigfr;
37 static ase_nullary_operation_f Qent_mpfr_zero, Qent_mpfr_one;
41 bigfr_print(Lisp_Object obj, Lisp_Object printcharfun, int SXE_UNUSED(unused))
43 Bufbyte *fstr = bigfr_to_string(XBIGFR_DATA(obj), 10);
44 write_c_string((char*)fstr, printcharfun);
46 fstr = (Bufbyte *)NULL;
51 bigfr_equal (Lisp_Object obj1, Lisp_Object obj2, int unused)
53 return bigfr_eq(XBIGFR_DATA(obj1), XBIGFR_DATA(obj2));
57 bigfr_hash (Lisp_Object obj, int unused)
59 return bigfr_hashcode(XBIGFR_DATA(obj));
63 bigfr_mark (Lisp_Object unused)
69 bigfr_finalise (void *header, int for_disksave)
73 ("Can't dump an emacs containing MPFR objects", Qt);
79 static const struct lrecord_description bigfr_description[] = {
80 { XD_OPAQUE_DATA_PTR, offsetof(Lisp_Bigfr, data) },
84 DEFINE_BASIC_LRECORD_IMPLEMENTATION("bigfr", bigfr,
85 bigfr_mark, bigfr_print, bigfr_finalise,
86 bigfr_equal, bigfr_hash,
87 bigfr_description, Lisp_Bigfr);
90 DEFUN ("bigfr-get-precision", Fbigfr_get_precision, 1, 1, 0, /*
91 Return the precision of bigfr F as an integer.
96 return make_integer((signed long)XBIGFR_GET_PREC(f));
100 #define MPFR_PREC_MIN 2UL
103 DEFUN ("bigfr-set-precision", Fbigfr_set_precision, 2, 2, 0, /*
104 Set the precision of F, a bigfr, to PRECISION, a nonnegative integer.
105 The new precision of F is returned. Note that the return value may differ
106 from PRECISION if the underlying library is unable to support exactly
107 PRECISION bits of precision.
114 if (INTP(precision)) {
115 prec = (XINT(precision) <= 0)
116 ? MPFR_PREC_MIN : (unsigned long)XINT(precision);
118 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
119 else if (BIGZP(precision)) {
120 prec = bigz_fits_ulong_p(XBIGZ_DATA(precision))
121 ? bigz_to_ulong(XBIGZ_DATA(precision))
124 #endif /* HAVE_MPZ */
126 dead_wrong_type_argument(Qintegerp, f);
130 XBIGFR_SET_PREC(f, prec);
131 return Fbigfr_get_precision(f);
135 Bufbyte *bigfr_to_string(mpfr_t f, int base)
140 const int sign = mpfr_sgn(f);
141 const int neg = (sign < 0) ? 1 : 0;
145 str = indef_to_string((indef)POS_INFINITY);
147 str = indef_to_string((indef)NEG_INFINITY);
150 } else if (mpfr_nan_p(f)) {
151 str = indef_to_string((indef)NOT_A_NUMBER);
157 str = (Bufbyte *)mpfr_get_str(NULL, &expt, base, 0, f,
159 len = strlen((char *)str) + 1; /* Count the null terminator */
161 /* Move digits down to insert a radix point */
163 /* We need room for a radix point and leading zeroes */
164 const int space = -expt + 2;
165 xrealloc_array(str, Bufbyte, len + space);
166 memmove(&str[space + neg], &str[neg], len - neg);
167 memset(&str[neg], '0', space);
170 } else if (expt < len) {
171 /* We just need room for a radix point */
172 xrealloc_array(str, Bufbyte, len + 1);
173 memmove(&str[expt + neg + 1],
176 str[expt + neg] = '.';
179 /* We need room for trailing zeroes */
180 xrealloc_array(str, Bufbyte, expt + 1);
181 memset(&str[len-1], '0', expt+2-len);
190 Lisp_Object read_bigfr_string(char *cp)
192 /* The mpfr version of bigfr_set_string (mpfr_set_str)
193 has the following limitation: if p starts with a '+'
194 sign, it does nothing; i.e., it leaves its bigfloat
196 Therefore, move p past any leading '+' signs. */
200 bigfr_init_prec(bfr, bigfr_get_default_prec());
205 bigfr_set_string(bfr, (const char*)cp, 0);
206 result = make_bigfr_bfr(bfr);
212 #if defined HAVE_MPC && defined WITH_MPC || \
213 defined HAVE_PSEUC && defined WITH_PSEUC
214 Lisp_Object read_bigc_string(char *cp)
220 BIGFR_INIT_PREC(bf_re, Qnil);
221 BIGFR_INIT_PREC(bf_im, Qnil);
223 /* MPC bigc_set_string has no effect
224 * with initial + sign */
227 bigfr_set_string(bf_re, cp, 0);
230 /* jump over a leading minus */
234 while ((*cp >= '0' && *cp <= '9') ||
238 /* read the imaginary part */
248 if ((*cp == 'i' || *cp == 'I') &&
250 /* expand +i to +1i and -i to -1i */
251 bigfr_set_long(bf_im, 1L);
252 } else if (sign == 0) {
253 /* obviously we did not have a+bi,
256 bigfr_set(bf_im, bf_re);
257 bigfr_set_long(bf_re, 0L);
259 bigfr_set_string(bf_im, cp, 0);
263 bigfr_neg(bf_im, bf_im);
265 result = make_bigc_bfr(bf_re, bf_im,
266 max(bigfr_get_prec(bf_re),
267 bigfr_get_prec(bf_im)));
278 ent_sum_BIGFR_T(Lisp_Object l, Lisp_Object r)
280 bigfr_set_prec(ent_scratch_bigfr,
281 max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
282 bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
283 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
286 ent_sum_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
288 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
289 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
290 bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
291 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
294 ent_sum_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
296 return ent_sum_BIGFR_T_INT_T(r, l);
298 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
300 ent_sum_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
302 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
303 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
304 bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
305 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
308 ent_sum_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
310 return ent_sum_BIGFR_T_BIGZ_T(r, l);
313 #if defined HAVE_MPQ && defined WITH_GMP
315 ent_sum_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
317 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
318 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
319 bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
320 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
323 ent_sum_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
325 return ent_sum_BIGFR_T_BIGQ_T(r, l);
328 #if defined HAVE_MPF && defined WITH_GMP
330 ent_sum_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
332 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
333 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
334 bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
335 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
338 ent_sum_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
340 return ent_sum_BIGFR_T_BIGF_T(r, l);
345 ent_sum_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
347 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
348 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
349 bigfr_add(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
350 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
353 ent_sum_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
355 return ent_sum_BIGFR_T_FLOAT_T(r, l);
361 ent_diff_BIGFR_T(Lisp_Object l, Lisp_Object r)
363 bigfr_set_prec(ent_scratch_bigfr,
364 max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
365 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
366 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
369 ent_diff_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
371 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
372 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
373 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
374 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
377 ent_diff_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
379 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
380 bigfr_set_long(ent_scratch_bigfr, ent_int(l));
381 bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
382 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
384 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
386 ent_diff_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
388 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
389 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
390 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
391 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
394 ent_diff_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
396 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
397 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
398 bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
399 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
402 #if defined HAVE_MPQ && defined WITH_GMP
404 ent_diff_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
406 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
407 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
408 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
409 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
412 ent_diff_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
414 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
415 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
416 bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
417 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
420 #if defined HAVE_MPF && defined WITH_GMP
422 ent_diff_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
424 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
425 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
426 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
427 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
430 ent_diff_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
432 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
433 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
434 bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
435 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
440 ent_diff_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
442 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
443 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
444 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
445 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
448 ent_diff_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
450 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
451 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
452 bigfr_sub(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
453 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
458 ent_neg_BIGFR_T(Lisp_Object l)
460 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
461 bigfr_neg(ent_scratch_bigfr, XBIGFR_DATA(l));
462 return make_bigfr_bfr(ent_scratch_bigfr);
466 ent_prod_BIGFR_T(Lisp_Object l, Lisp_Object r)
468 bigfr_set_prec(ent_scratch_bigfr,
469 max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
470 bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
471 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
474 ent_prod_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
476 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
477 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
478 bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
479 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
482 ent_prod_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
484 return ent_prod_BIGFR_T_INT_T(r, l);
486 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
488 ent_prod_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
490 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
491 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
492 bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
493 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
496 ent_prod_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
498 return ent_prod_BIGFR_T_BIGZ_T(r, l);
501 #if defined HAVE_MPQ && defined WITH_GMP
503 ent_prod_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
505 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
506 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
507 bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
508 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
511 ent_prod_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
513 return ent_prod_BIGFR_T_BIGQ_T(r, l);
516 #if defined HAVE_MPF && defined WITH_GMP
518 ent_prod_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
520 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
521 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
522 bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
523 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
526 ent_prod_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
528 return ent_prod_BIGFR_T_BIGF_T(r, l);
533 ent_prod_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
535 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
536 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
537 bigfr_mul(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
538 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
541 ent_prod_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
543 return ent_prod_BIGFR_T_FLOAT_T(r, l);
548 ent_div_BIGFR_T(Lisp_Object l, Lisp_Object r)
550 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
551 int lsgn = bigfr_sign(XBIGFR_DATA(l));
553 return make_indef(POS_INFINITY);
555 return make_indef(NEG_INFINITY);
557 return make_indef(NOT_A_NUMBER);
559 bigfr_set_prec(ent_scratch_bigfr,
560 max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
561 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
562 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
565 ent_div_BIGFR_T_INT_T(Lisp_Object l, Lisp_Object r)
567 if (ent_int(r) == 0) {
568 int lsgn = bigfr_sign(XBIGFR_DATA(l));
570 return make_indef(POS_INFINITY);
572 return make_indef(NEG_INFINITY);
574 return make_indef(NOT_A_NUMBER);
577 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
578 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
579 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
580 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
583 ent_div_INT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
585 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
586 EMACS_INT rl = ent_int(l);
588 return make_indef(POS_INFINITY);
590 return make_indef(NEG_INFINITY);
592 return make_indef(NOT_A_NUMBER);
595 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
596 bigfr_set_long(ent_scratch_bigfr, ent_int(l));
597 bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
598 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
600 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
602 ent_div_BIGFR_T_BIGZ_T(Lisp_Object l, Lisp_Object r)
604 if (bigz_sign(XBIGZ_DATA(r)) == 0) {
605 int lsgn = bigfr_sign(XBIGFR_DATA(l));
607 return make_indef(POS_INFINITY);
609 return make_indef(NEG_INFINITY);
611 return make_indef(NOT_A_NUMBER);
614 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
615 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
616 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
617 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
620 ent_div_BIGZ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
622 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
623 int lsgn = bigz_sign(XBIGZ_DATA(l));
625 return make_indef(POS_INFINITY);
627 return make_indef(NEG_INFINITY);
629 return make_indef(NOT_A_NUMBER);
632 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
633 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
634 bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
635 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
638 #if defined HAVE_MPQ && defined WITH_GMP
640 ent_div_BIGFR_T_BIGQ_T(Lisp_Object l, Lisp_Object r)
642 if (bigq_sign(XBIGQ_DATA(r)) == 0) {
643 int lsgn = bigfr_sign(XBIGFR_DATA(l));
645 return make_indef(POS_INFINITY);
647 return make_indef(NEG_INFINITY);
649 return make_indef(NOT_A_NUMBER);
652 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
653 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
654 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
655 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
658 ent_div_BIGQ_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
660 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
661 int lsgn = bigq_sign(XBIGQ_DATA(l));
663 return make_indef(POS_INFINITY);
665 return make_indef(NEG_INFINITY);
667 return make_indef(NOT_A_NUMBER);
670 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
671 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
672 bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
673 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
676 #if defined HAVE_MPF && defined WITH_GMP
678 ent_div_BIGFR_T_BIGF_T(Lisp_Object l, Lisp_Object r)
680 if (bigf_sign(XBIGF_DATA(r)) == 0) {
681 int lsgn = bigfr_sign(XBIGFR_DATA(l));
683 return make_indef(POS_INFINITY);
685 return make_indef(NEG_INFINITY);
687 return make_indef(NOT_A_NUMBER);
690 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
691 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
692 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
693 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
696 ent_div_BIGF_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
698 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
699 int lsgn = bigf_sign(XBIGF_DATA(l));
701 return make_indef(POS_INFINITY);
703 return make_indef(NEG_INFINITY);
705 return make_indef(NOT_A_NUMBER);
708 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
709 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
710 bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
711 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
716 ent_div_BIGFR_T_FLOAT_T(Lisp_Object l, Lisp_Object r)
718 if (XFLOAT_DATA(r) == 0.0f) {
719 int lsgn = bigfr_sign(XBIGFR_DATA(l));
721 return make_indef(POS_INFINITY);
723 return make_indef(NEG_INFINITY);
725 return make_indef(NOT_A_NUMBER);
728 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
729 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
730 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
731 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
734 ent_div_FLOAT_T_BIGFR_T(Lisp_Object l, Lisp_Object r)
736 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
737 if (XFLOAT_DATA(l) > 0.0f)
738 return make_indef(POS_INFINITY);
739 else if (XFLOAT_DATA(r) < 0.0f)
740 return make_indef(NEG_INFINITY);
742 return make_indef(NOT_A_NUMBER);
745 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
746 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
747 bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
748 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
753 ent_inv_BIGFR_T(Lisp_Object r)
755 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
756 return make_indef(POS_INFINITY);
758 bigfr_set_long(ent_scratch_bigfr, 1L);
759 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(r));
760 bigfr_div(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
761 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
764 ent_rem_BIGFR_T(Lisp_Object unused, Lisp_Object r)
766 return Qent_mpfr_zero;
769 ent_mod_BIGFR_T(Lisp_Object l, Lisp_Object r)
771 if (bigfr_sign(XBIGFR_DATA(r)) == 0) {
772 return Qent_mpfr_zero;
774 bigfr_set_prec(ent_scratch_bigfr,
775 max(XBIGFR_GET_PREC(l), XBIGFR_GET_PREC(r)));
776 bigfr_div(ent_scratch_bigfr, XBIGFR_DATA(l), XBIGFR_DATA(r));
777 bigfr_trunc(ent_scratch_bigfr, ent_scratch_bigfr);
778 bigfr_mul(ent_scratch_bigfr, ent_scratch_bigfr, XBIGFR_DATA(r));
779 bigfr_sub(ent_scratch_bigfr, XBIGFR_DATA(l), ent_scratch_bigfr);
780 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
784 ent_pow_BIGFR_T_integer(Lisp_Object l, Lisp_Object r)
788 if (NILP(Fnonnegativep(r))) {
790 ent_pow_BIGFR_T_integer(l, ent_unop_neg(r)));
795 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
796 } else if (BIGZP(r)) {
797 if (bigz_fits_long_p(XBIGZ_DATA(r)))
798 expo = bigz_to_long(XBIGZ_DATA(r));
800 Fsignal(Qarith_error, list1(r));
803 Fsignal(Qarith_error, list1(r));
807 bigfr_set_prec(ent_scratch_bigfr, XBIGFR_GET_PREC(l));
808 bigfr_pow(ent_scratch_bigfr, XBIGFR_DATA(l), expo);
809 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
815 ent_lt_bigfr(Lisp_Object l, Lisp_Object r)
817 return (bigfr_lt(XBIGFR_DATA(l), XBIGFR_DATA(r)));
820 ent_lt_bigfr_int(Lisp_Object l, Lisp_Object r)
822 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
823 return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
826 ent_lt_int_bigfr(Lisp_Object l, Lisp_Object r)
828 bigfr_set_long(ent_scratch_bigfr, ent_int(l));
829 return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
831 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
833 ent_lt_bigfr_bigz(Lisp_Object l, Lisp_Object r)
835 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
836 return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
839 ent_lt_bigz_bigfr(Lisp_Object l, Lisp_Object r)
841 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
842 return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
845 #if defined HAVE_MPQ && defined WITH_GMP
847 ent_lt_bigfr_bigq(Lisp_Object l, Lisp_Object r)
849 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
850 return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
853 ent_lt_bigq_bigfr(Lisp_Object l, Lisp_Object r)
855 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
856 return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
859 #if defined HAVE_MPF && defined WITH_GMP
861 ent_lt_bigfr_bigf(Lisp_Object l, Lisp_Object r)
863 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
864 return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
867 ent_lt_bigf_bigfr(Lisp_Object l, Lisp_Object r)
869 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
870 return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
875 ent_lt_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
877 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
878 return (bigfr_lt(XBIGFR_DATA(l), ent_scratch_bigfr));
881 ent_lt_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
883 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
884 return (bigfr_lt(ent_scratch_bigfr, XBIGFR_DATA(r)));
889 ent_gt_bigfr(Lisp_Object l, Lisp_Object r)
891 return (bigfr_gt(XBIGFR_DATA(l), XBIGFR_DATA(r)));
894 ent_gt_bigfr_int(Lisp_Object l, Lisp_Object r)
896 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
897 return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
900 ent_gt_int_bigfr(Lisp_Object l, Lisp_Object r)
902 bigfr_set_long(ent_scratch_bigfr, ent_int(l));
903 return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
905 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
907 ent_gt_bigfr_bigz(Lisp_Object l, Lisp_Object r)
909 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
910 return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
913 ent_gt_bigz_bigfr(Lisp_Object l, Lisp_Object r)
915 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
916 return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
919 #if defined HAVE_MPQ && defined WITH_GMP
921 ent_gt_bigfr_bigq(Lisp_Object l, Lisp_Object r)
923 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
924 return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
927 ent_gt_bigq_bigfr(Lisp_Object l, Lisp_Object r)
929 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
930 return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
933 #if defined HAVE_MPF && defined WITH_GMP
935 ent_gt_bigfr_bigf(Lisp_Object l, Lisp_Object r)
937 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
938 return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
941 ent_gt_bigf_bigfr(Lisp_Object l, Lisp_Object r)
943 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
944 return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
949 ent_gt_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
951 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
952 return (bigfr_gt(XBIGFR_DATA(l), ent_scratch_bigfr));
955 ent_gt_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
957 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
958 return (bigfr_gt(ent_scratch_bigfr, XBIGFR_DATA(r)));
963 ent_eq_bigfr(Lisp_Object l, Lisp_Object r)
965 return (bigfr_eq(XBIGFR_DATA(l), XBIGFR_DATA(r)));
968 ent_eq_bigfr_int(Lisp_Object l, Lisp_Object r)
970 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
971 return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
974 ent_eq_int_bigfr(Lisp_Object l, Lisp_Object r)
976 bigfr_set_long(ent_scratch_bigfr, ent_int(l));
977 return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
979 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
981 ent_eq_bigfr_bigz(Lisp_Object l, Lisp_Object r)
983 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
984 return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
987 ent_eq_bigz_bigfr(Lisp_Object l, Lisp_Object r)
989 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
990 return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
993 #if defined HAVE_MPQ && defined WITH_GMP
995 ent_eq_bigfr_bigq(Lisp_Object l, Lisp_Object r)
997 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
998 return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1001 ent_eq_bigq_bigfr(Lisp_Object l, Lisp_Object r)
1003 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
1004 return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1007 #if defined HAVE_MPF && defined WITH_GMP
1009 ent_eq_bigfr_bigf(Lisp_Object l, Lisp_Object r)
1011 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
1012 return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1015 ent_eq_bigf_bigfr(Lisp_Object l, Lisp_Object r)
1017 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
1018 return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1023 ent_eq_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
1025 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
1026 return (bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1029 ent_eq_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
1031 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
1032 return (bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1037 ent_ne_bigfr(Lisp_Object l, Lisp_Object r)
1039 return !(bigfr_eq(XBIGFR_DATA(l), XBIGFR_DATA(r)));
1042 ent_ne_bigfr_int(Lisp_Object l, Lisp_Object r)
1044 bigfr_set_long(ent_scratch_bigfr, ent_int(r));
1045 return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1048 ent_ne_int_bigfr(Lisp_Object l, Lisp_Object r)
1050 bigfr_set_long(ent_scratch_bigfr, ent_int(l));
1051 return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1053 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1055 ent_ne_bigfr_bigz(Lisp_Object l, Lisp_Object r)
1057 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(r));
1058 return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1061 ent_ne_bigz_bigfr(Lisp_Object l, Lisp_Object r)
1063 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(l));
1064 return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1067 #if defined HAVE_MPQ && defined WITH_GMP
1069 ent_ne_bigfr_bigq(Lisp_Object l, Lisp_Object r)
1071 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(r));
1072 return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1075 ent_ne_bigq_bigfr(Lisp_Object l, Lisp_Object r)
1077 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(l));
1078 return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1081 #if defined HAVE_MPF && defined WITH_GMP
1083 ent_ne_bigfr_bigf(Lisp_Object l, Lisp_Object r)
1085 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(r));
1086 return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1089 ent_ne_bigf_bigfr(Lisp_Object l, Lisp_Object r)
1091 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(l));
1092 return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1097 ent_ne_bigfr_fpfloat(Lisp_Object l, Lisp_Object r)
1099 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(r));
1100 return !(bigfr_eq(XBIGFR_DATA(l), ent_scratch_bigfr));
1103 ent_ne_fpfloat_bigfr(Lisp_Object l, Lisp_Object r)
1105 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(l));
1106 return !(bigfr_eq(ent_scratch_bigfr, XBIGFR_DATA(r)));
1111 static inline Lisp_Object
1112 _ent_lift_INT_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1114 unsigned long precision = la->precision;
1115 return make_bigfr(ent_int(number), precision);
1118 static inline Lisp_Object
1119 _ent_lift_BIGFR_T_INT_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
1121 return make_int(bigfr_to_long(XBIGFR_DATA(number)));
1124 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1125 static inline Lisp_Object
1126 _ent_lift_BIGZ_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1128 unsigned long precision = la->precision;
1130 bigfr_set_prec(ent_scratch_bigfr, precision);
1131 bigfr_set_bigz(ent_scratch_bigfr, XBIGZ_DATA(number));
1132 return make_bigfr_bfr(ent_scratch_bigfr);
1135 static inline Lisp_Object
1136 _ent_lift_BIGFR_T_BIGZ_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
1138 bigz_set_bigfr(ent_scratch_bigz, XBIGFR_DATA(number));
1139 return make_bigz_bz(ent_scratch_bigz);
1141 #endif /* HAVE_MPZ */
1143 #if defined HAVE_MPQ && defined WITH_GMP
1144 static inline Lisp_Object
1145 _ent_lift_BIGQ_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1147 unsigned long precision = la->precision;
1149 bigfr_set_prec(ent_scratch_bigfr, precision);
1150 bigfr_set_bigq(ent_scratch_bigfr, XBIGQ_DATA(number));
1151 return make_bigfr_bfr(ent_scratch_bigfr);
1153 #endif /* HAVE_MPQ */
1155 #if defined HAVE_MPF && defined WITH_GMP
1156 static inline Lisp_Object
1157 _ent_lift_BIGF_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1159 unsigned long precision = la->precision;
1161 bigfr_set_prec(ent_scratch_bigfr, precision);
1162 bigfr_set_bigf(ent_scratch_bigfr, XBIGF_DATA(number));
1163 return make_bigfr_bfr(ent_scratch_bigfr);
1166 static inline Lisp_Object
1167 _ent_lift_BIGFR_T_BIGF_T(Lisp_Object number, ent_lift_args_t la)
1169 unsigned long precision = la->precision;
1171 bigf_set_prec(ent_scratch_bigf, precision);
1172 bigf_set_bigfr(ent_scratch_bigf, XBIGFR_DATA(number));
1173 return make_bigf_bf(ent_scratch_bigf);
1175 #endif /* HAVE_MPF */
1178 static inline Lisp_Object
1179 _ent_lift_FLOAT_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1181 unsigned long precision = la->precision;
1183 bigfr_set_prec(ent_scratch_bigfr, precision);
1184 bigfr_set_fpfloat(ent_scratch_bigfr, XFLOAT_DATA(number));
1185 return make_bigfr_bfr(ent_scratch_bigfr);
1188 static inline Lisp_Object
1189 _ent_lift_BIGFR_T_FLOAT_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
1191 return make_float(bigfr_to_fpfloat(XBIGFR_DATA(number)));
1195 static inline Lisp_Object
1196 _ent_lift_BIGFR_T_BIGFR_T(Lisp_Object number, ent_lift_args_t la)
1198 unsigned long precision = la->precision;
1200 bigfr_set_prec(ent_scratch_bigfr, precision);
1201 bigfr_set(ent_scratch_bigfr, XBIGFR_DATA(number));
1202 return ent_mpfr_wipe_indef(ent_scratch_bigfr);
1206 ent_mpfr_zerop(Lisp_Object l)
1208 return (bigfr_sign(XBIGFR_DATA(l)) == 0);
1212 ent_mpfr_onep(Lisp_Object l)
1214 return (bigfr_to_fpfloat(XBIGFR_DATA(l)) == 1.0f);
1218 ent_mpfr_unitp(Lisp_Object unused)
1225 ent_mpfr_nullary_optable_init(void)
1227 Qent_mpfr_zero = make_bigfr(0.0f, internal_get_precision(Qnil));
1228 Qent_mpfr_one = make_bigfr(1.0f, internal_get_precision(Qnil));
1229 staticpro(&Qent_mpfr_zero);
1230 staticpro(&Qent_mpfr_one);
1232 ent_nullop_register(ASE_NULLARY_OP_ZERO, BIGFR_T, Qent_mpfr_zero);
1233 ent_nullop_register(ASE_NULLARY_OP_ONE, BIGFR_T, Qent_mpfr_one);
1237 ent_mpfr_unary_optable_init(void)
1239 ent_unop_register(ASE_UNARY_OP_NEG, BIGFR_T, ent_neg_BIGFR_T);
1240 ent_unop_register(ASE_UNARY_OP_INV, BIGFR_T, ent_inv_BIGFR_T);
1244 ent_mpfr_binary_optable_init(void)
1247 ent_binop_register(ASE_BINARY_OP_SUM,
1248 BIGFR_T, BIGFR_T, ent_sum_BIGFR_T);
1249 ent_binop_register(ASE_BINARY_OP_SUM,
1250 BIGFR_T, INT_T, ent_sum_BIGFR_T_INT_T);
1251 ent_binop_register(ASE_BINARY_OP_SUM,
1252 INT_T, BIGFR_T, ent_sum_INT_T_BIGFR_T);
1253 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1254 ent_binop_register(ASE_BINARY_OP_SUM,
1255 BIGFR_T, BIGZ_T, ent_sum_BIGFR_T_BIGZ_T);
1256 ent_binop_register(ASE_BINARY_OP_SUM,
1257 BIGZ_T, BIGFR_T, ent_sum_BIGZ_T_BIGFR_T);
1259 #if defined HAVE_MPQ && defined WITH_GMP
1260 ent_binop_register(ASE_BINARY_OP_SUM,
1261 BIGFR_T, BIGQ_T, ent_sum_BIGFR_T_BIGQ_T);
1262 ent_binop_register(ASE_BINARY_OP_SUM,
1263 BIGQ_T, BIGFR_T, ent_sum_BIGQ_T_BIGFR_T);
1265 #if defined HAVE_MPF && defined WITH_GMP
1266 ent_binop_register(ASE_BINARY_OP_SUM,
1267 BIGFR_T, BIGF_T, ent_sum_BIGFR_T_BIGF_T);
1268 ent_binop_register(ASE_BINARY_OP_SUM,
1269 BIGF_T, BIGFR_T, ent_sum_BIGF_T_BIGFR_T);
1272 ent_binop_register(ASE_BINARY_OP_SUM,
1273 FLOAT_T, BIGFR_T, ent_sum_FLOAT_T_BIGFR_T);
1274 ent_binop_register(ASE_BINARY_OP_SUM,
1275 BIGFR_T, FLOAT_T, ent_sum_BIGFR_T_FLOAT_T);
1278 ent_binop_register(ASE_BINARY_OP_DIFF,
1279 BIGFR_T, BIGFR_T, ent_diff_BIGFR_T);
1280 ent_binop_register(ASE_BINARY_OP_DIFF,
1281 BIGFR_T, INT_T, ent_diff_BIGFR_T_INT_T);
1282 ent_binop_register(ASE_BINARY_OP_DIFF,
1283 INT_T, BIGFR_T, ent_diff_INT_T_BIGFR_T);
1284 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1285 ent_binop_register(ASE_BINARY_OP_DIFF,
1286 BIGFR_T, BIGZ_T, ent_diff_BIGFR_T_BIGZ_T);
1287 ent_binop_register(ASE_BINARY_OP_DIFF,
1288 BIGZ_T, BIGFR_T, ent_diff_BIGZ_T_BIGFR_T);
1290 #if defined HAVE_MPQ && defined WITH_GMP
1291 ent_binop_register(ASE_BINARY_OP_DIFF,
1292 BIGFR_T, BIGQ_T, ent_diff_BIGFR_T_BIGQ_T);
1293 ent_binop_register(ASE_BINARY_OP_DIFF,
1294 BIGQ_T, BIGFR_T, ent_diff_BIGQ_T_BIGFR_T);
1296 #if defined HAVE_MPF && defined WITH_GMP
1297 ent_binop_register(ASE_BINARY_OP_DIFF,
1298 BIGFR_T, BIGF_T, ent_diff_BIGFR_T_BIGF_T);
1299 ent_binop_register(ASE_BINARY_OP_DIFF,
1300 BIGF_T, BIGFR_T, ent_diff_BIGF_T_BIGFR_T);
1303 ent_binop_register(ASE_BINARY_OP_DIFF,
1304 FLOAT_T, BIGFR_T, ent_diff_FLOAT_T_BIGFR_T);
1305 ent_binop_register(ASE_BINARY_OP_DIFF,
1306 BIGFR_T, FLOAT_T, ent_diff_BIGFR_T_FLOAT_T);
1310 ent_binop_register(ASE_BINARY_OP_PROD,
1311 BIGFR_T, BIGFR_T, ent_prod_BIGFR_T);
1312 ent_binop_register(ASE_BINARY_OP_PROD,
1313 BIGFR_T, INT_T, ent_prod_BIGFR_T_INT_T);
1314 ent_binop_register(ASE_BINARY_OP_PROD,
1315 INT_T, BIGFR_T, ent_prod_INT_T_BIGFR_T);
1316 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1317 ent_binop_register(ASE_BINARY_OP_PROD,
1318 BIGFR_T, BIGZ_T, ent_prod_BIGFR_T_BIGZ_T);
1319 ent_binop_register(ASE_BINARY_OP_PROD,
1320 BIGZ_T, BIGFR_T, ent_prod_BIGZ_T_BIGFR_T);
1322 #if defined HAVE_MPQ && defined WITH_GMP
1323 ent_binop_register(ASE_BINARY_OP_PROD,
1324 BIGFR_T, BIGQ_T, ent_prod_BIGFR_T_BIGQ_T);
1325 ent_binop_register(ASE_BINARY_OP_PROD,
1326 BIGQ_T, BIGFR_T, ent_prod_BIGQ_T_BIGFR_T);
1328 #if defined HAVE_MPF && defined WITH_GMP
1329 ent_binop_register(ASE_BINARY_OP_PROD,
1330 BIGFR_T, BIGF_T, ent_prod_BIGFR_T_BIGF_T);
1331 ent_binop_register(ASE_BINARY_OP_PROD,
1332 BIGF_T, BIGFR_T, ent_prod_BIGF_T_BIGFR_T);
1335 ent_binop_register(ASE_BINARY_OP_PROD,
1336 FLOAT_T, BIGFR_T, ent_prod_FLOAT_T_BIGFR_T);
1337 ent_binop_register(ASE_BINARY_OP_PROD,
1338 BIGFR_T, FLOAT_T, ent_prod_BIGFR_T_FLOAT_T);
1341 ent_binop_register(ASE_BINARY_OP_DIV,
1342 BIGFR_T, BIGFR_T, ent_div_BIGFR_T);
1343 ent_binop_register(ASE_BINARY_OP_DIV,
1344 BIGFR_T, INT_T, ent_div_BIGFR_T_INT_T);
1345 ent_binop_register(ASE_BINARY_OP_DIV,
1346 INT_T, BIGFR_T, ent_div_INT_T_BIGFR_T);
1347 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1348 ent_binop_register(ASE_BINARY_OP_DIV,
1349 BIGFR_T, BIGZ_T, ent_div_BIGFR_T_BIGZ_T);
1350 ent_binop_register(ASE_BINARY_OP_DIV,
1351 BIGZ_T, BIGFR_T, ent_div_BIGZ_T_BIGFR_T);
1353 #if defined HAVE_MPQ && defined WITH_GMP
1354 ent_binop_register(ASE_BINARY_OP_DIV,
1355 BIGFR_T, BIGQ_T, ent_div_BIGFR_T_BIGQ_T);
1356 ent_binop_register(ASE_BINARY_OP_DIV,
1357 BIGQ_T, BIGFR_T, ent_div_BIGQ_T_BIGFR_T);
1359 #if defined HAVE_MPF && defined WITH_GMP
1360 ent_binop_register(ASE_BINARY_OP_DIV,
1361 BIGFR_T, BIGF_T, ent_div_BIGFR_T_BIGF_T);
1362 ent_binop_register(ASE_BINARY_OP_DIV,
1363 BIGF_T, BIGFR_T, ent_div_BIGF_T_BIGFR_T);
1366 ent_binop_register(ASE_BINARY_OP_DIV,
1367 FLOAT_T, BIGFR_T, ent_div_FLOAT_T_BIGFR_T);
1368 ent_binop_register(ASE_BINARY_OP_DIV,
1369 BIGFR_T, FLOAT_T, ent_div_BIGFR_T_FLOAT_T);
1372 ent_binop_register(ASE_BINARY_OP_QUO,
1373 BIGFR_T, BIGFR_T, ent_div_BIGFR_T);
1374 ent_binop_register(ASE_BINARY_OP_QUO,
1375 BIGFR_T, INT_T, ent_div_BIGFR_T_INT_T);
1376 ent_binop_register(ASE_BINARY_OP_QUO,
1377 INT_T, BIGFR_T, ent_div_INT_T_BIGFR_T);
1378 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1379 ent_binop_register(ASE_BINARY_OP_QUO,
1380 BIGFR_T, BIGZ_T, ent_div_BIGFR_T_BIGZ_T);
1381 ent_binop_register(ASE_BINARY_OP_QUO,
1382 BIGZ_T, BIGFR_T, ent_div_BIGZ_T_BIGFR_T);
1384 #if defined HAVE_MPQ && defined WITH_GMP
1385 ent_binop_register(ASE_BINARY_OP_QUO,
1386 BIGFR_T, BIGQ_T, ent_div_BIGFR_T_BIGQ_T);
1387 ent_binop_register(ASE_BINARY_OP_QUO,
1388 BIGQ_T, BIGFR_T, ent_div_BIGQ_T_BIGFR_T);
1390 #if defined HAVE_MPF && defined WITH_GMP
1391 ent_binop_register(ASE_BINARY_OP_QUO,
1392 BIGFR_T, BIGF_T, ent_div_BIGFR_T_BIGF_T);
1393 ent_binop_register(ASE_BINARY_OP_QUO,
1394 BIGF_T, BIGFR_T, ent_div_BIGF_T_BIGFR_T);
1397 ent_binop_register(ASE_BINARY_OP_QUO,
1398 FLOAT_T, BIGFR_T, ent_div_FLOAT_T_BIGFR_T);
1399 ent_binop_register(ASE_BINARY_OP_QUO,
1400 BIGFR_T, FLOAT_T, ent_div_BIGFR_T_FLOAT_T);
1404 ent_binop_register(ASE_BINARY_OP_MOD,
1405 BIGFR_T, BIGFR_T, ent_mod_BIGFR_T);
1406 ent_binop_register(ASE_BINARY_OP_REM,
1407 BIGFR_T, BIGFR_T, ent_rem_BIGFR_T);
1408 ent_binop_register(ASE_BINARY_OP_REM,
1409 INT_T, BIGFR_T, ent_rem_BIGFR_T);
1410 ent_binop_register(ASE_BINARY_OP_REM,
1411 INDEF_T, BIGFR_T, ent_rem_BIGFR_T);
1412 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1413 ent_binop_register(ASE_BINARY_OP_REM,
1414 BIGZ_T, BIGFR_T, ent_rem_BIGFR_T);
1416 #if defined HAVE_MPQ && defined WITH_GMP
1417 ent_binop_register(ASE_BINARY_OP_REM,
1418 BIGQ_T, BIGFR_T, ent_rem_BIGFR_T);
1420 #if defined HAVE_MPF && defined WITH_GMP
1421 ent_binop_register(ASE_BINARY_OP_REM,
1422 BIGF_T, BIGFR_T, ent_rem_BIGFR_T);
1425 ent_binop_register(ASE_BINARY_OP_REM,
1426 FLOAT_T, BIGFR_T, ent_rem_BIGFR_T);
1430 ent_binop_register(ASE_BINARY_OP_POW,
1431 BIGFR_T, INT_T, ent_pow_BIGFR_T_integer);
1432 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1433 ent_binop_register(ASE_BINARY_OP_POW,
1434 BIGFR_T, BIGZ_T, ent_pow_BIGFR_T_integer);
1440 ent_mpfr_unary_reltable_init(void)
1442 ent_unrel_register(ASE_UNARY_REL_ZEROP, BIGFR_T, ent_mpfr_zerop);
1443 ent_unrel_register(ASE_UNARY_REL_ONEP, BIGFR_T, ent_mpfr_onep);
1444 ent_unrel_register(ASE_UNARY_REL_UNITP, BIGFR_T, ent_mpfr_unitp);
1448 ent_mpfr_binary_reltable_init(void)
1450 ent_binrel_register(ASE_BINARY_REL_LESSP,
1451 BIGFR_T, BIGFR_T, ent_lt_bigfr);
1452 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1453 BIGFR_T, BIGFR_T, ent_gt_bigfr);
1454 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1455 BIGFR_T, BIGFR_T, ent_eq_bigfr);
1456 ent_binrel_register(ASE_BINARY_REL_NEQP,
1457 BIGFR_T, BIGFR_T, ent_ne_bigfr);
1459 ent_binrel_register(ASE_BINARY_REL_LESSP,
1460 BIGFR_T, INT_T, ent_lt_bigfr_int);
1461 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1462 BIGFR_T, INT_T, ent_gt_bigfr_int);
1463 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1464 BIGFR_T, INT_T, ent_eq_bigfr_int);
1465 ent_binrel_register(ASE_BINARY_REL_NEQP,
1466 BIGFR_T, INT_T, ent_ne_bigfr_int);
1468 ent_binrel_register(ASE_BINARY_REL_LESSP,
1469 INT_T, BIGFR_T, ent_lt_int_bigfr);
1470 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1471 INT_T, BIGFR_T, ent_gt_int_bigfr);
1472 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1473 INT_T, BIGFR_T, ent_eq_int_bigfr);
1474 ent_binrel_register(ASE_BINARY_REL_NEQP,
1475 INT_T, BIGFR_T, ent_ne_int_bigfr);
1477 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1478 ent_binrel_register(ASE_BINARY_REL_LESSP,
1479 BIGFR_T, BIGZ_T, ent_lt_bigfr_bigz);
1480 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1481 BIGFR_T, BIGZ_T, ent_gt_bigfr_bigz);
1482 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1483 BIGFR_T, BIGZ_T, ent_eq_bigfr_bigz);
1484 ent_binrel_register(ASE_BINARY_REL_NEQP,
1485 BIGFR_T, BIGZ_T, ent_ne_bigfr_bigz);
1487 ent_binrel_register(ASE_BINARY_REL_LESSP,
1488 BIGZ_T, BIGFR_T, ent_lt_bigz_bigfr);
1489 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1490 BIGZ_T, BIGFR_T, ent_gt_bigz_bigfr);
1491 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1492 BIGZ_T, BIGFR_T, ent_eq_bigz_bigfr);
1493 ent_binrel_register(ASE_BINARY_REL_NEQP,
1494 BIGZ_T, BIGFR_T, ent_ne_bigz_bigfr);
1496 #if defined HAVE_MPQ && defined WITH_GMP
1497 ent_binrel_register(ASE_BINARY_REL_LESSP,
1498 BIGFR_T, BIGQ_T, ent_lt_bigfr_bigq);
1499 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1500 BIGFR_T, BIGQ_T, ent_gt_bigfr_bigq);
1501 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1502 BIGFR_T, BIGQ_T, ent_eq_bigfr_bigq);
1503 ent_binrel_register(ASE_BINARY_REL_NEQP,
1504 BIGFR_T, BIGQ_T, ent_ne_bigfr_bigq);
1506 ent_binrel_register(ASE_BINARY_REL_LESSP,
1507 BIGQ_T, BIGFR_T, ent_lt_bigq_bigfr);
1508 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1509 BIGQ_T, BIGFR_T, ent_gt_bigq_bigfr);
1510 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1511 BIGQ_T, BIGFR_T, ent_eq_bigq_bigfr);
1512 ent_binrel_register(ASE_BINARY_REL_NEQP,
1513 BIGQ_T, BIGFR_T, ent_ne_bigq_bigfr);
1515 #if defined HAVE_MPF && defined WITH_GMP
1516 ent_binrel_register(ASE_BINARY_REL_LESSP,
1517 BIGFR_T, BIGF_T, ent_lt_bigfr_bigf);
1518 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1519 BIGFR_T, BIGF_T, ent_gt_bigfr_bigf);
1520 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1521 BIGFR_T, BIGF_T, ent_eq_bigfr_bigf);
1522 ent_binrel_register(ASE_BINARY_REL_NEQP,
1523 BIGFR_T, BIGF_T, ent_ne_bigfr_bigf);
1525 ent_binrel_register(ASE_BINARY_REL_LESSP,
1526 BIGF_T, BIGFR_T, ent_lt_bigf_bigfr);
1527 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1528 BIGF_T, BIGFR_T, ent_gt_bigf_bigfr);
1529 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1530 BIGF_T, BIGFR_T, ent_eq_bigf_bigfr);
1531 ent_binrel_register(ASE_BINARY_REL_NEQP,
1532 BIGF_T, BIGFR_T, ent_ne_bigf_bigfr);
1535 ent_binrel_register(ASE_BINARY_REL_LESSP,
1536 BIGFR_T, FLOAT_T, ent_lt_bigfr_fpfloat);
1537 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1538 BIGFR_T, FLOAT_T, ent_gt_bigfr_fpfloat);
1539 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1540 BIGFR_T, FLOAT_T, ent_eq_bigfr_fpfloat);
1541 ent_binrel_register(ASE_BINARY_REL_NEQP,
1542 BIGFR_T, FLOAT_T, ent_ne_bigfr_fpfloat);
1544 ent_binrel_register(ASE_BINARY_REL_LESSP,
1545 FLOAT_T, BIGFR_T, ent_lt_fpfloat_bigfr);
1546 ent_binrel_register(ASE_BINARY_REL_GREATERP,
1547 FLOAT_T, BIGFR_T, ent_gt_fpfloat_bigfr);
1548 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1549 FLOAT_T, BIGFR_T, ent_eq_fpfloat_bigfr);
1550 ent_binrel_register(ASE_BINARY_REL_NEQP,
1551 FLOAT_T, BIGFR_T, ent_ne_fpfloat_bigfr);
1556 ent_mpfr_lifttable_init(void)
1558 ent_lift_register(BIGFR_T, BIGFR_T, _ent_lift_BIGFR_T_BIGFR_T);
1559 ent_lift_register(BIGFR_T, INT_T, _ent_lift_BIGFR_T_INT_T);
1560 ent_lift_register(INT_T, BIGFR_T, _ent_lift_INT_T_BIGFR_T);
1561 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
1562 ent_lift_register(BIGFR_T, BIGZ_T, _ent_lift_BIGFR_T_BIGZ_T);
1563 ent_lift_register(BIGZ_T, BIGFR_T, _ent_lift_BIGZ_T_BIGFR_T);
1565 #if defined HAVE_MPQ && defined WITH_GMP
1566 ent_lift_register(BIGQ_T, BIGFR_T, _ent_lift_BIGQ_T_BIGFR_T);
1568 #if defined HAVE_MPF && defined WITH_GMP
1569 ent_lift_register(BIGFR_T, BIGF_T, _ent_lift_BIGFR_T_BIGF_T);
1570 ent_lift_register(BIGF_T, BIGFR_T, _ent_lift_BIGF_T_BIGFR_T);
1573 ent_lift_register(BIGFR_T, FLOAT_T, _ent_lift_BIGFR_T_FLOAT_T);
1574 ent_lift_register(FLOAT_T, BIGFR_T, _ent_lift_FLOAT_T_BIGFR_T);
1576 ent_lift_register(INDEF_T, BIGFR_T, ent_lift_INDEF_T_COMPARABLE);
1580 void init_optables_BIGFR_T(void)
1582 ent_mpfr_nullary_optable_init();
1583 ent_mpfr_unary_optable_init();
1584 ent_mpfr_binary_optable_init();
1585 ent_mpfr_unary_reltable_init();
1586 ent_mpfr_binary_reltable_init();
1587 ent_mpfr_lifttable_init();
1590 void init_ent_mpfr(void)
1592 bigfr_init(ent_scratch_bigfr);
1594 Veuler = make_bigfr(0.0, 2048UL);
1595 bigfr_set_long(ent_scratch_bigfr, 1L);
1596 mpfr_exp(XBIGFR_DATA(Veuler), ent_scratch_bigfr, GMP_RNDN);
1598 Veuler_mascheroni = make_bigfr(0.0, 2048UL);
1599 mpfr_const_euler(XBIGFR_DATA(Veuler_mascheroni), GMP_RNDN);
1601 Vpi = make_bigfr(0.0, 2048UL);
1602 mpfr_const_pi(XBIGFR_DATA(Vpi), GMP_RNDN);
1605 void syms_of_ent_mpfr(void)
1607 INIT_LRECORD_IMPLEMENTATION(bigfr);
1609 DEFSUBR(Fbigfr_get_precision);
1610 DEFSUBR(Fbigfr_set_precision);
1612 bigfr_set_default_prec(128UL);
1615 void vars_of_ent_mpfr(void)
1617 /* define pi and e */
1619 /* just some dummy values atm, to make the dumper smile */
1620 Veuler = make_int(1L);
1621 Veuler_mascheroni = make_int(1L);
1624 DEFVAR_CONST_LISP("euler", &Veuler /*
1625 The value of Euler's constant e (2.7182818...).
1627 DEFVAR_CONST_LISP("euler-mascheroni", &Veuler_mascheroni /*
1628 The value of the Euler-Mascheroni constant (0.5772156...).
1630 DEFVAR_CONST_LISP("pi", &Vpi /*
1631 The value of pi (3.1415926...).
1634 Fprovide(intern("bigfr"));