2 ent-gaussian.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 */
30 #include "ent-float.h"
32 #include "ent-gaussian.h"
37 bigg ent_scratch_bigg;
38 static ase_nullary_operation_f Qent_gaussian_zero, Qent_gaussian_one;
42 bigg_print(Lisp_Object obj, Lisp_Object printcharfun, int SXE_UNUSED(escapeflag))
44 Bufbyte *fstr = bigg_to_string(XBIGG_DATA(obj), 10);
45 write_c_string((char*)fstr, printcharfun);
47 fstr = (Bufbyte *)NULL;
52 bigg_equal(Lisp_Object obj1, Lisp_Object obj2, int depth)
54 return bigg_eql(XBIGG_DATA(obj1), XBIGG_DATA(obj2));
61 bigg_hash(Lisp_Object obj, int depth)
63 return bigg_hashcode(XBIGG_DATA(obj));
70 bigg_mark(Lisp_Object obj)
79 bigg_finalise(void *header, int for_disksave)
83 ("Can't dump an emacs containing "
84 "pseudo-gaussian objects",Qt);
90 static const struct lrecord_description bigg_description[] = {
91 { XD_OPAQUE_DATA_PTR, offsetof(Lisp_Bigg, data) },
95 DEFINE_BASIC_LRECORD_IMPLEMENTATION("bigg", bigg,
96 bigg_mark, bigg_print, bigg_finalise,
97 bigg_equal, bigg_hash,
98 bigg_description, Lisp_Bigg);
100 DEFUN("make-bigg", Fmake_bigg, 2, 2, 0, /*
101 Return the Gaussian number whose rational component is REAL-PART
102 and whose imaginary component is IMAGINARY-PART.
104 (real_part, imaginary_part))
106 CHECK_COMPARABLE(real_part);
107 CHECK_COMPARABLE(imaginary_part);
110 Lisp_Object tmp_r = Fcoerce_number(real_part, Qbigz, Qnil);
111 Lisp_Object tmp_i = Fcoerce_number(imaginary_part, Qbigz, Qnil);
112 return make_bigg_bz(XBIGZ_DATA(tmp_r), XBIGZ_DATA(tmp_i));
117 /* basic functions */
118 void bigg_init(bigg g)
120 bigz_init(bigg_re(g));
121 bigz_init(bigg_im(g));
124 void bigg_fini(bigg g)
126 bigz_fini(bigg_re(g));
127 bigz_fini(bigg_im(g));
130 unsigned long bigg_hashcode(bigg g)
132 return (bigz_hashcode(bigg_re(g)) ^
133 bigz_hashcode(bigg_im(g)));
136 Bufbyte *bigg_to_string(bigg g, int base)
140 int intg_len, imag_len;
143 intg_str = (Bufbyte*)bigz_to_string(bigg_re(g), base);
144 imag_str = (Bufbyte*)bigz_to_string(bigg_im(g), base);
146 intg_len = strlen((char*)intg_str);
147 imag_len = strlen((char*)imag_str);
149 sign = bigz_sign(bigg_im(g));
150 neg = (sign >= 0) ? 1 : 0;
152 /* now append the imaginary string */
153 XREALLOC_ARRAY(intg_str, Bufbyte, intg_len + neg + imag_len + 2);
155 intg_str[intg_len] = '+';
156 memmove(&intg_str[intg_len + neg],
159 intg_str[intg_len+neg+imag_len] = 'i';
160 intg_str[intg_len+neg+imag_len+1] = '\0';
166 /***** Bigg: converting assignments *****/
167 void bigg_set(bigg g1,bigg g2)
169 bigz_set(bigg_re(g1), bigg_re(g2));
170 bigz_set(bigg_im(g1), bigg_im(g2));
173 void bigg_set_long(bigg g, long l)
175 bigz_set_long(bigg_re(g), l);
176 bigz_set_long(bigg_im(g), 0L);
179 void bigg_set_long_long(bigg g, long l1, long l2)
181 bigz_set_long(bigg_re(g), l1);
182 bigz_set_long(bigg_im(g), l2);
185 void bigg_set_ulong(bigg g, unsigned long ul)
187 bigz_set_ulong(bigg_re(g), ul);
188 bigz_set_ulong(bigg_im(g), 0UL);
191 void bigg_set_ulong_ulong(bigg g, unsigned long ul1, unsigned long ul2)
193 bigz_set_ulong(bigg_re(g), ul1);
194 bigz_set_ulong(bigg_im(g), ul2);
197 void bigg_set_bigz(bigg g, bigz z)
199 bigz_set(bigg_re(g), z);
200 bigz_set_long(bigg_im(g), 0L);
203 void bigg_set_bigz_bigz(bigg g, bigz z1, bigz z2)
205 bigz_set(bigg_re(g), z1);
206 bigz_set(bigg_im(g), z2);
209 /* void bigc_set_bigg(bigc c, bigg g)
211 * bigc_set_bigfr_bigfr(bigg_re(g), z1);
215 /***** Bigg: comparisons *****/
216 int bigg_eql(bigg g1, bigg g2)
218 return ((bigz_eql(bigg_re(g1), bigg_re(g2))) &&
219 (bigz_eql(bigg_im(g1), bigg_im(g2))));
222 /***** Bigg: arithmetic *****/
223 #if defined HAVE_MPFR && defined WITH_MPFR
224 void bigg_abs(bigfr res, bigg g)
226 /* the absolute archimedean valuation of a+bi is defined as:
229 bigz accu1, accu2, bz;
234 bigz_mul(accu1, bigg_re(g), bigg_re(g));
235 bigz_mul(accu2, bigg_im(g), bigg_im(g));
236 bigz_add(bz, accu1, accu2);
238 bigfr_set_bigz(res, bz);
239 bigfr_sqrt(res, res);
247 void bigg_norm(bigz res, bigg g)
249 /* norm is the square of the absolute archimedean valuation */
254 bigz_mul(accu1, bigg_re(g), bigg_re(g));
255 bigz_mul(accu2, bigg_im(g), bigg_im(g));
256 bigz_add(res, accu1, accu2);
262 void bigg_neg(bigg res, bigg g)
264 /* negation is defined point-wise */
265 bigz_neg(bigg_re(res), bigg_re(g));
266 bigz_neg(bigg_im(res), bigg_im(g));
269 void bigg_conj(bigg res, bigg g)
272 bigz_neg(bigg_im(res), bigg_im(res));
275 void bigg_add(bigg res, bigg g1, bigg g2)
277 /* addition is defined point-wise */
282 bigz_add(accu1, bigg_re(g1), bigg_re(g2));
283 bigz_add(accu2, bigg_im(g1), bigg_im(g2));
284 bigg_set_bigz_bigz(res, accu1, accu2);
290 void bigg_sub(bigg res, bigg g1, bigg g2)
292 /* subtraction is defined point-wise */
293 bigz_sub(bigg_re(res), bigg_re(g1), bigg_re(g2));
294 bigz_sub(bigg_im(res), bigg_im(g1), bigg_im(g2));
297 void bigg_mul(bigg res, bigg g1, bigg g2)
299 /* multiplication is defined as:
300 * (a + bi)*(c + di) = (ac - bd) + (ad + bc)i
302 bigz accu1, accu2, accu3, accu4;
308 bigz_mul(accu1, bigg_re(g1), bigg_re(g2));
309 bigz_mul(accu2, bigg_im(g1), bigg_im(g2));
310 bigz_mul(accu3, bigg_re(g1), bigg_im(g2));
311 bigz_mul(accu4, bigg_im(g1), bigg_re(g2));
313 bigz_sub(bigg_re(res), accu1, accu2);
314 bigz_add(bigg_im(res), accu3, accu4);
322 void bigg_div(bigg res, bigg g1, bigg g2)
324 /* division is defined as:
325 * (a + bi) div (c + di) = ((a+bi)*(c-di)) div (c*c+d*d)
333 /* compute: c^2 + d^2 */
334 bigz_mul(accu1, bigg_re(g2), bigg_re(g2));
335 bigz_mul(accu2, bigg_im(g2), bigg_im(g2));
336 bigz_add(accu1, accu1, accu2);
338 /* do normal multiplication with conjugate of g2 */
339 bigg_conj(accug, g2);
340 bigg_mul(accug, g1, accug);
342 bigg_set(res, accug);
344 /* now divide (g1*conj(g2)) by c^2+d^2 (point-wise) */
345 bigz_div(bigg_re(res), bigg_re(accug), accu1);
346 bigz_div(bigg_im(res), bigg_im(accug), accu1);
353 void bigg_mod(bigg res, bigg g1, bigg g2)
355 /* the modulo relation is defined as:
356 * (a + bi) mod (c + di) ~
357 * (a+bi) - ((a+bi) div (c-di)) * (c+di)
362 /* do normal division */
363 bigg_div(accug, g1, g2);
365 /* now re-multiply g2 */
366 bigg_mul(accug, accug, g2);
368 /* and find the difference */
369 bigg_sub(res, g1, accug);
374 void bigg_pow(bigg res, bigg g1, unsigned long g2)
376 #if defined(HAVE_MPZ) && defined(WITH_GMP)
378 bigz bin, resintg, resimag, tmpbz1, tmpbz2, tmpbz3, intg, imag;
389 bigz_set_long(resintg, 0L);
390 bigz_set_long(resimag, 0L);
392 bigz_set(intg, bigg_re(g1));
393 bigz_set(imag, bigg_im(g1));
395 /* we compute using the binomial coefficients */
396 for (i=0; i<=g2; i++) {
397 mpz_bin_uiui(bin, g2, i);
399 /* real part changes */
400 bigz_pow(tmpbz1, intg, g2-i);
401 bigz_pow(tmpbz2, imag, i);
402 bigz_mul(tmpbz3, tmpbz1, tmpbz2);
403 bigz_mul(bin, bin, tmpbz3);
405 bigz_add(resintg, resintg, bin);
406 } else if (i % 4 == 2) {
407 bigz_sub(resintg, resintg, bin);
410 /* imag part changes */
411 bigz_pow(tmpbz1, intg, g2-i);
412 bigz_pow(tmpbz2, imag, i);
413 bigz_mul(tmpbz3, tmpbz1, tmpbz2);
414 bigz_mul(bin, bin, tmpbz3);
416 bigz_add(resimag, resimag, bin);
417 } else if (i % 4 == 3) {
418 bigz_sub(resimag, resimag, bin);
423 bigg_set_bigz_bigz(res, resintg, resimag);
434 bigg_set_long_long(res, 0L, 0L);
438 Lisp_Object read_bigg_string(char *cp)
449 /* MPZ bigz_set_string has no effect
450 * with initial + sign */
457 /* jump over a leading minus */
461 while ((*cp >= '0' && *cp <= '9'))
464 /* MPZ cannot read numbers with characters after them.
465 * See limitations below in convert GMP-MPZ strings
469 bigz_set_string(bz_re, (char *)end, 0);
472 /* read the imaginary part */
482 if ((*cp == 'i' || *cp == 'I') && (sign == 1)) {
483 /* expand +i to +1i and -i to -1i */
484 bigz_set_long(bz_im, 1L);
485 } else if ((*cp == 'i' || *cp == 'I') && (sign == -1)) {
486 /* expand +i to +1i and -i to -1i */
487 bigz_set_long(bz_im, -1L);
488 } else if (sign == 0) {
489 /* obviously we did not have a+bi,
492 bigz_set(bz_im, bz_re);
493 bigz_set_long(bz_re, 0L);
498 while ((*cp >= '0' && *cp <= '9'))
502 bigz_set_string(bz_im, (char *)end, 0);
506 result = make_bigg_bz(bz_re, bz_im);
515 ent_gaussian_zerop(Lisp_Object o)
517 return (bigz_sign(bigg_re(XBIGG_DATA(o))) == 0 &&
518 bigz_sign(bigg_im(XBIGG_DATA(o))) == 0);
522 ent_gaussian_onep(Lisp_Object o)
524 return ((bigz_fits_long_p(bigg_re(XBIGG_DATA(o))) &&
525 bigz_to_long(bigg_re(XBIGG_DATA(o))) == 1L) &&
526 bigz_sign(bigg_im(XBIGG_DATA(o))) == 0);
530 ent_gaussian_unitp(Lisp_Object o)
532 return (!ent_gaussian_zerop(o) &&
533 (bigz_fits_long_p(bigg_re(XBIGG_DATA(o))) &&
534 (bigz_to_long(bigg_re(XBIGG_DATA(o))) == 0L ||
535 bigz_to_long(bigg_re(XBIGG_DATA(o))) == 1L ||
536 bigz_to_long(bigg_re(XBIGG_DATA(o))) == -1L)) &&
537 (bigz_fits_long_p(bigg_im(XBIGG_DATA(o))) &&
538 (bigz_to_long(bigg_im(XBIGG_DATA(o))) == 0L ||
539 bigz_to_long(bigg_im(XBIGG_DATA(o))) == 1L ||
540 bigz_to_long(bigg_im(XBIGG_DATA(o))) == -1L)));
543 static inline Lisp_Object
544 ent_sum_BIGG_T(Lisp_Object l, Lisp_Object r)
546 bigg_add(ent_scratch_bigg, XBIGG_DATA(l), XBIGG_DATA(r));
547 return make_bigg_bg(ent_scratch_bigg);
549 static inline Lisp_Object
550 ent_sum_BIGG_T_COMPARABLE(Lisp_Object l, Lisp_Object r)
554 r = ent_lift(r, BIGZ_T, NULL);
556 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(r));
557 bigg_add(ent_scratch_bigg, XBIGG_DATA(l), ent_scratch_bigg);
558 return make_bigg_bg(ent_scratch_bigg);
560 static inline Lisp_Object
561 ent_sum_COMPARABLE_BIGG_T(Lisp_Object l, Lisp_Object r)
565 l = ent_lift(l, BIGZ_T, NULL);
567 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(l));
568 bigg_add(ent_scratch_bigg, ent_scratch_bigg, XBIGG_DATA(r));
569 return make_bigg_bg(ent_scratch_bigg);
572 static inline Lisp_Object
573 ent_diff_BIGG_T(Lisp_Object l, Lisp_Object r)
575 bigg_sub(ent_scratch_bigg, XBIGG_DATA(l), XBIGG_DATA(r));
576 return make_bigg_bg(ent_scratch_bigg);
578 static inline Lisp_Object
579 ent_diff_BIGG_T_COMPARABLE(Lisp_Object l, Lisp_Object r)
583 r = ent_lift(r, BIGZ_T, NULL);
585 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(r));
586 bigg_sub(ent_scratch_bigg, XBIGG_DATA(l), ent_scratch_bigg);
587 return make_bigg_bg(ent_scratch_bigg);
589 static inline Lisp_Object
590 ent_diff_COMPARABLE_BIGG_T(Lisp_Object l, Lisp_Object r)
594 l = ent_lift(l, BIGZ_T, NULL);
596 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(l));
597 bigg_sub(ent_scratch_bigg, ent_scratch_bigg, XBIGG_DATA(r));
598 return make_bigg_bg(ent_scratch_bigg);
601 static inline Lisp_Object
602 ent_neg_BIGG_T(Lisp_Object l)
604 bigg_neg(ent_scratch_bigg, XBIGG_DATA(l));
605 return make_bigg_bg(ent_scratch_bigg);
608 static inline Lisp_Object
609 ent_prod_BIGG_T(Lisp_Object l, Lisp_Object r)
611 bigg_mul(ent_scratch_bigg, XBIGG_DATA(l), XBIGG_DATA(r));
612 return make_bigg_bg(ent_scratch_bigg);
614 static inline Lisp_Object
615 ent_prod_BIGG_T_COMPARABLE(Lisp_Object l, Lisp_Object r)
619 r = ent_lift(r, BIGZ_T, NULL);
621 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(r));
622 bigg_mul(ent_scratch_bigg, XBIGG_DATA(l), ent_scratch_bigg);
623 return make_bigg_bg(ent_scratch_bigg);
625 static inline Lisp_Object
626 ent_prod_COMPARABLE_BIGG_T(Lisp_Object l, Lisp_Object r)
630 l = ent_lift(l, BIGZ_T, NULL);
632 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(l));
633 bigg_mul(ent_scratch_bigg, ent_scratch_bigg, XBIGG_DATA(r));
634 return make_bigg_bg(ent_scratch_bigg);
637 static inline Lisp_Object
638 ent_div_BIGG_T(Lisp_Object l, Lisp_Object r)
640 if (ent_gaussian_zerop(r)) {
641 if (!ent_gaussian_zerop(l)) {
642 return make_indef(COMPLEX_INFINITY);
644 return make_indef(NOT_A_NUMBER);
647 bigg_div(ent_scratch_bigg, XBIGG_DATA(l), XBIGG_DATA(r));
648 return make_bigg_bg(ent_scratch_bigg);
650 static inline Lisp_Object
651 ent_div_BIGG_T_COMPARABLE(Lisp_Object l, Lisp_Object r)
655 if (ent_unrel_zerop(l)) {
656 if (!ent_gaussian_zerop(l)) {
657 return make_indef(COMPLEX_INFINITY);
659 return make_indef(NOT_A_NUMBER);
663 r = ent_lift(r, BIGZ_T, NULL);
665 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(r));
666 bigg_div(ent_scratch_bigg, XBIGG_DATA(l), ent_scratch_bigg);
667 return make_bigg_bg(ent_scratch_bigg);
669 static inline Lisp_Object
670 ent_div_COMPARABLE_BIGG_T(Lisp_Object l, Lisp_Object r)
674 if (ent_gaussian_zerop(r)) {
675 if (!ent_unrel_zerop(l)) {
676 return make_indef(COMPLEX_INFINITY);
678 return make_indef(NOT_A_NUMBER);
682 l = ent_lift(l, BIGZ_T, NULL);
684 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(l));
685 bigg_div(ent_scratch_bigg, ent_scratch_bigg, XBIGG_DATA(r));
686 return make_bigg_bg(ent_scratch_bigg);
689 #if defined HAVE_MPC && defined WITH_MPC || \
690 defined HAVE_PSEUC && defined WITH_PSEUC
691 static inline Lisp_Object
692 ent_quo_BIGG_T(Lisp_Object l, Lisp_Object r)
694 Lisp_Object tmp_l, tmp_r;
696 if (ent_gaussian_zerop(r)) {
697 if (!ent_gaussian_zerop(l)) {
698 return make_indef(COMPLEX_INFINITY);
700 return make_indef(NOT_A_NUMBER);
704 bigc_set_prec(ent_scratch_bigc, internal_get_precision(Qnil));
705 tmp_l = Fcoerce_number(l, Qbigc, Qnil);
706 tmp_r = Fcoerce_number(r, Qbigc, Qnil);
707 bigc_div(ent_scratch_bigc, XBIGC_DATA(tmp_l), XBIGC_DATA(tmp_r));
708 return make_bigc_bc(ent_scratch_bigc);
710 static inline Lisp_Object
711 ent_quo_BIGG_T_COMPARABLE(Lisp_Object l, Lisp_Object r)
715 if (ent_unrel_zerop(r)) {
716 if (!ent_gaussian_zerop(l)) {
717 return make_indef(COMPLEX_INFINITY);
719 return make_indef(NOT_A_NUMBER);
723 l = ent_lift(l, BIGC_T, NULL);
724 return ent_binop(ASE_BINARY_OP_QUO, l, r);
726 static inline Lisp_Object
727 ent_quo_COMPARABLE_BIGG_T(Lisp_Object l, Lisp_Object r)
731 if (ent_gaussian_zerop(r)) {
732 if (!ent_unrel_zerop(l)) {
733 return make_indef(COMPLEX_INFINITY);
735 return make_indef(NOT_A_NUMBER);
739 r = ent_lift(r, BIGC_T, NULL);
740 return ent_binop(ASE_BINARY_OP_QUO, l, r);
744 static inline Lisp_Object
745 ent_inv_BIGG_T(Lisp_Object r)
747 if (ent_gaussian_zerop(r)) {
748 return make_indef(COMPLEX_INFINITY);
750 bigg_div(ent_scratch_bigg,
751 XBIGG_DATA(Qent_gaussian_one), XBIGG_DATA(r));
752 return make_bigg_bg(ent_scratch_bigg);
754 static inline Lisp_Object
755 ent_rem_BIGG_T(Lisp_Object l, Lisp_Object r)
757 if (ent_gaussian_zerop(r)) {
758 return make_bigg(0, 0);
760 bigg_mod(ent_scratch_bigg, XBIGG_DATA(l), XBIGG_DATA(r));
761 return make_bigg_bg(ent_scratch_bigg);
763 static inline Lisp_Object
764 ent_pow_BIGG_T_integer(Lisp_Object l, Lisp_Object r)
766 long unsigned int expo = 0UL;
770 } else if (BIGZP(r)) {
771 if (bigz_fits_ulong_p(XBIGZ_DATA(r)))
772 expo = bigz_to_ulong(XBIGZ_DATA(r));
774 Fsignal(Qarith_error, r);
776 Fsignal(Qdomain_error, r);
778 bigg_pow(ent_scratch_bigg, XBIGG_DATA(l), expo);
779 return make_bigg_bg(ent_scratch_bigg);
784 ent_eq_bigg(Lisp_Object l, Lisp_Object r)
786 return (bigz_eql(bigg_re(XBIGG_DATA(l)), bigg_re(XBIGG_DATA(r))) &&
787 bigz_eql(bigg_im(XBIGG_DATA(l)), bigg_im(XBIGG_DATA(r))));
791 ent_ne_bigg(Lisp_Object l, Lisp_Object r)
793 return !(bigz_eql(bigg_re(XBIGG_DATA(l)), bigg_re(XBIGG_DATA(r))) &&
794 bigz_eql(bigg_im(XBIGG_DATA(l)), bigg_im(XBIGG_DATA(r))));
798 static inline Lisp_Object
799 ent_vallt_BIGG_T(Lisp_Object l, Lisp_Object r)
805 bigg_norm(ent_scratch_bigz, XBIGG_DATA(l));
806 bigg_norm(b2, XBIGG_DATA(r));
807 result = bigz_lt(ent_scratch_bigz, b2);
810 return (result) ? Qt : Qnil;
812 static inline Lisp_Object
813 ent_valgt_BIGG_T(Lisp_Object l, Lisp_Object r)
819 bigg_norm(ent_scratch_bigz, XBIGG_DATA(l));
820 bigg_norm(b2, XBIGG_DATA(r));
821 result = bigz_gt(ent_scratch_bigz, b2);
824 return (result) ? Qt : Qnil;
826 static inline Lisp_Object
827 ent_valeq_BIGG_T(Lisp_Object l, Lisp_Object r)
833 bigg_norm(ent_scratch_bigz, XBIGG_DATA(l));
834 bigg_norm(b2, XBIGG_DATA(r));
835 result = bigz_eql(ent_scratch_bigz, b2);
838 return (result) ? Qt : Qnil;
840 static inline Lisp_Object
841 ent_valne_BIGG_T(Lisp_Object l, Lisp_Object r)
847 bigg_norm(ent_scratch_bigz, XBIGG_DATA(l));
848 bigg_norm(b2, XBIGG_DATA(r));
849 result = bigz_eql(ent_scratch_bigz, b2);
852 return (result) ? Qnil : Qt;
858 ent_lift_all_BIGG_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
860 number = ent_lift(number, BIGZ_T, NULL);
861 bigg_set_bigz(ent_scratch_bigg, XBIGZ_DATA(number));
862 return make_bigg_bg(ent_scratch_bigg);
865 #if defined HAVE_MPC && defined WITH_MPC || \
866 defined HAVE_PSEUC && defined WITH_PSEUC
868 ent_lift_BIGC_T_BIGG_T(Lisp_Object number, ent_lift_args_t SXE_UNUSED(la))
872 re = Freal_part(number);
873 re = ent_lift(re, BIGZ_T, NULL);
874 im = Fimaginary_part(number);
875 im = ent_lift(im, BIGZ_T, NULL);
877 return make_bigg_bz(XBIGZ_DATA(re), XBIGZ_DATA(im));
883 ent_gaussian_nullary_optable_init(void)
885 Qent_gaussian_zero = make_bigg(0L, 0L);
886 Qent_gaussian_one = make_bigg(1L, 0L);
887 staticpro(&Qent_gaussian_zero);
888 staticpro(&Qent_gaussian_one);
890 ent_nullop_register(ASE_NULLARY_OP_ZERO, BIGG_T, Qent_gaussian_zero);
891 ent_nullop_register(ASE_NULLARY_OP_ONE, BIGG_T, Qent_gaussian_one);
895 ent_gaussian_unary_optable_init(void)
897 ent_unop_register(ASE_UNARY_OP_NEG, BIGG_T, ent_neg_BIGG_T);
898 ent_unop_register(ASE_UNARY_OP_INV, BIGG_T, ent_inv_BIGG_T);
902 ent_gaussian_binary_optable_init(void)
905 ent_binop_register(ASE_BINARY_OP_SUM,
906 BIGG_T, BIGG_T, ent_sum_BIGG_T);
907 ent_binop_register(ASE_BINARY_OP_SUM,
908 BIGG_T, INT_T, ent_sum_BIGG_T_COMPARABLE);
909 ent_binop_register(ASE_BINARY_OP_SUM,
910 INT_T, BIGG_T, ent_sum_COMPARABLE_BIGG_T);
911 #if defined HAVE_MPZ && (defined WITH_GMP || defined WITH_MP)
912 ent_binop_register(ASE_BINARY_OP_SUM,
913 BIGG_T, BIGZ_T, ent_sum_BIGG_T_COMPARABLE);
914 ent_binop_register(ASE_BINARY_OP_SUM,
915 BIGZ_T, BIGG_T, ent_sum_COMPARABLE_BIGG_T);
917 #if defined HAVE_MPQ && defined WITH_GMP
918 ent_binop_register(ASE_BINARY_OP_SUM,
919 BIGG_T, BIGQ_T, ent_sum_BIGG_T_COMPARABLE);
920 ent_binop_register(ASE_BINARY_OP_SUM,
921 BIGQ_T, BIGG_T, ent_sum_COMPARABLE_BIGG_T);
923 #if defined HAVE_MPF && defined WITH_GMP
924 ent_binop_register(ASE_BINARY_OP_SUM,
925 BIGG_T, BIGF_T, ent_sum_BIGG_T_COMPARABLE);
926 ent_binop_register(ASE_BINARY_OP_SUM,
927 BIGF_T, BIGG_T, ent_sum_COMPARABLE_BIGG_T);
929 #if defined HAVE_MPFR && defined WITH_MPFR
930 ent_binop_register(ASE_BINARY_OP_SUM,
931 BIGG_T, BIGFR_T, ent_sum_BIGG_T_COMPARABLE);
932 ent_binop_register(ASE_BINARY_OP_SUM,
933 BIGFR_T, BIGG_T, ent_sum_COMPARABLE_BIGG_T);
936 ent_binop_register(ASE_BINARY_OP_SUM,
937 BIGG_T, FLOAT_T, ent_sum_BIGG_T_COMPARABLE);
938 ent_binop_register(ASE_BINARY_OP_SUM,
939 FLOAT_T, BIGG_T, ent_sum_COMPARABLE_BIGG_T);
942 ent_binop_register(ASE_BINARY_OP_DIFF,
943 BIGG_T, BIGG_T, ent_diff_BIGG_T);
944 ent_binop_register(ASE_BINARY_OP_DIFF,
945 BIGG_T, INT_T, ent_diff_BIGG_T_COMPARABLE);
946 ent_binop_register(ASE_BINARY_OP_DIFF,
947 INT_T, BIGG_T, ent_diff_COMPARABLE_BIGG_T);
948 ent_binop_register(ASE_BINARY_OP_DIFF,
949 BIGG_T, BIGZ_T, ent_diff_BIGG_T_COMPARABLE);
950 ent_binop_register(ASE_BINARY_OP_DIFF,
951 BIGZ_T, BIGG_T, ent_diff_COMPARABLE_BIGG_T);
952 #if defined HAVE_MPQ && defined WITH_GMP
953 ent_binop_register(ASE_BINARY_OP_DIFF,
954 BIGG_T, BIGQ_T, ent_diff_BIGG_T_COMPARABLE);
955 ent_binop_register(ASE_BINARY_OP_DIFF,
956 BIGQ_T, BIGG_T, ent_diff_COMPARABLE_BIGG_T);
958 #if defined HAVE_MPF && defined WITH_GMP
959 ent_binop_register(ASE_BINARY_OP_DIFF,
960 BIGG_T, BIGF_T, ent_diff_BIGG_T_COMPARABLE);
961 ent_binop_register(ASE_BINARY_OP_DIFF,
962 BIGF_T, BIGG_T, ent_diff_COMPARABLE_BIGG_T);
964 #if defined HAVE_MPFR && defined WITH_MPFR
965 ent_binop_register(ASE_BINARY_OP_DIFF,
966 BIGG_T, BIGFR_T, ent_diff_BIGG_T_COMPARABLE);
967 ent_binop_register(ASE_BINARY_OP_DIFF,
968 BIGFR_T, BIGG_T, ent_diff_COMPARABLE_BIGG_T);
971 ent_binop_register(ASE_BINARY_OP_DIFF,
972 BIGG_T, FLOAT_T, ent_diff_BIGG_T_COMPARABLE);
973 ent_binop_register(ASE_BINARY_OP_DIFF,
974 FLOAT_T, BIGG_T, ent_diff_COMPARABLE_BIGG_T);
977 ent_binop_register(ASE_BINARY_OP_PROD,
978 BIGG_T, BIGG_T, ent_prod_BIGG_T);
979 ent_binop_register(ASE_BINARY_OP_PROD,
980 BIGG_T, INT_T, ent_prod_BIGG_T_COMPARABLE);
981 ent_binop_register(ASE_BINARY_OP_PROD,
982 INT_T, BIGG_T, ent_prod_COMPARABLE_BIGG_T);
983 ent_binop_register(ASE_BINARY_OP_PROD,
984 BIGG_T, BIGZ_T, ent_prod_BIGG_T_COMPARABLE);
985 ent_binop_register(ASE_BINARY_OP_PROD,
986 BIGZ_T, BIGG_T, ent_prod_COMPARABLE_BIGG_T);
987 #if defined HAVE_MPQ && defined WITH_GMP
988 ent_binop_register(ASE_BINARY_OP_PROD,
989 BIGG_T, BIGQ_T, ent_prod_BIGG_T_COMPARABLE);
990 ent_binop_register(ASE_BINARY_OP_PROD,
991 BIGQ_T, BIGG_T, ent_prod_COMPARABLE_BIGG_T);
993 #if defined HAVE_MPF && defined WITH_GMP
994 ent_binop_register(ASE_BINARY_OP_PROD,
995 BIGG_T, BIGF_T, ent_prod_BIGG_T_COMPARABLE);
996 ent_binop_register(ASE_BINARY_OP_PROD,
997 BIGF_T, BIGG_T, ent_prod_COMPARABLE_BIGG_T);
999 #if defined HAVE_MPFR && defined WITH_MPFR
1000 ent_binop_register(ASE_BINARY_OP_PROD,
1001 BIGG_T, BIGFR_T, ent_prod_BIGG_T_COMPARABLE);
1002 ent_binop_register(ASE_BINARY_OP_PROD,
1003 BIGFR_T, BIGG_T, ent_prod_COMPARABLE_BIGG_T);
1006 ent_binop_register(ASE_BINARY_OP_PROD,
1007 BIGG_T, FLOAT_T, ent_prod_BIGG_T_COMPARABLE);
1008 ent_binop_register(ASE_BINARY_OP_PROD,
1009 FLOAT_T, BIGG_T, ent_prod_COMPARABLE_BIGG_T);
1012 /* divisions and quotients */
1013 ent_binop_register(ASE_BINARY_OP_DIV,
1014 BIGG_T, BIGG_T, ent_div_BIGG_T);
1015 ent_binop_register(ASE_BINARY_OP_DIV,
1016 BIGG_T, INT_T, ent_div_BIGG_T_COMPARABLE);
1017 ent_binop_register(ASE_BINARY_OP_DIV,
1018 INT_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1019 ent_binop_register(ASE_BINARY_OP_DIV,
1020 BIGG_T, BIGZ_T, ent_div_BIGG_T_COMPARABLE);
1021 ent_binop_register(ASE_BINARY_OP_DIV,
1022 BIGZ_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1023 #if defined HAVE_MPQ && defined WITH_GMP
1024 ent_binop_register(ASE_BINARY_OP_DIV,
1025 BIGG_T, BIGQ_T, ent_div_BIGG_T_COMPARABLE);
1026 ent_binop_register(ASE_BINARY_OP_DIV,
1027 BIGQ_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1029 #if defined HAVE_MPF && defined WITH_GMP
1030 ent_binop_register(ASE_BINARY_OP_DIV,
1031 BIGG_T, BIGF_T, ent_div_BIGG_T_COMPARABLE);
1032 ent_binop_register(ASE_BINARY_OP_DIV,
1033 BIGF_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1035 #if defined HAVE_MPFR && defined WITH_MPFR
1036 ent_binop_register(ASE_BINARY_OP_DIV,
1037 BIGG_T, BIGFR_T, ent_div_BIGG_T_COMPARABLE);
1038 ent_binop_register(ASE_BINARY_OP_DIV,
1039 BIGFR_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1042 ent_binop_register(ASE_BINARY_OP_DIV,
1043 BIGG_T, FLOAT_T, ent_div_BIGG_T_COMPARABLE);
1044 ent_binop_register(ASE_BINARY_OP_DIV,
1045 FLOAT_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1048 #if defined HAVE_MPC && defined WITH_MPC || \
1049 defined HAVE_PSEUC && defined WITH_PSEUC
1050 ent_binop_register(ASE_BINARY_OP_QUO,
1051 BIGG_T, BIGG_T, ent_quo_BIGG_T);
1052 ent_binop_register(ASE_BINARY_OP_QUO,
1053 BIGG_T, BIGZ_T, ent_quo_BIGG_T_COMPARABLE);
1054 ent_binop_register(ASE_BINARY_OP_QUO,
1055 BIGZ_T, BIGG_T, ent_quo_COMPARABLE_BIGG_T);
1056 #if defined HAVE_MPQ && defined WITH_GMP
1057 ent_binop_register(ASE_BINARY_OP_QUO,
1058 BIGG_T, BIGQ_T, ent_quo_BIGG_T_COMPARABLE);
1059 ent_binop_register(ASE_BINARY_OP_QUO,
1060 BIGQ_T, BIGG_T, ent_quo_COMPARABLE_BIGG_T);
1062 #if defined HAVE_MPF && defined WITH_GMP
1063 ent_binop_register(ASE_BINARY_OP_QUO,
1064 BIGG_T, BIGF_T, ent_quo_BIGG_T_COMPARABLE);
1065 ent_binop_register(ASE_BINARY_OP_QUO,
1066 BIGF_T, BIGG_T, ent_quo_COMPARABLE_BIGG_T);
1068 #if defined HAVE_MPFR && defined WITH_MPFR
1069 ent_binop_register(ASE_BINARY_OP_QUO,
1070 BIGG_T, BIGFR_T, ent_quo_BIGG_T_COMPARABLE);
1071 ent_binop_register(ASE_BINARY_OP_QUO,
1072 BIGFR_T, BIGG_T, ent_quo_COMPARABLE_BIGG_T);
1075 ent_binop_register(ASE_BINARY_OP_QUO,
1076 BIGG_T, FLOAT_T, ent_quo_BIGG_T_COMPARABLE);
1077 ent_binop_register(ASE_BINARY_OP_QUO,
1078 FLOAT_T, BIGG_T, ent_quo_COMPARABLE_BIGG_T);
1080 #else /* !HAVE_MPC */
1081 ent_binop_register(ASE_BINARY_OP_QUO,
1082 BIGG_T, BIGG_T, ent_div_BIGG_T);
1083 ent_binop_register(ASE_BINARY_OP_QUO,
1084 BIGG_T, BIGZ_T, ent_div_BIGG_T_COMPARABLE);
1085 ent_binop_register(ASE_BINARY_OP_QUO,
1086 BIGZ_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1087 #if defined HAVE_MPQ && defined WITH_GMP
1088 ent_binop_register(ASE_BINARY_OP_QUO,
1089 BIGG_T, BIGQ_T, ent_div_BIGG_T_COMPARABLE);
1090 ent_binop_register(ASE_BINARY_OP_QUO,
1091 BIGQ_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1093 #if defined HAVE_MPF && defined WITH_GMP
1094 ent_binop_register(ASE_BINARY_OP_QUO,
1095 BIGG_T, BIGF_T, ent_div_BIGG_T_COMPARABLE);
1096 ent_binop_register(ASE_BINARY_OP_QUO,
1097 BIGF_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1099 #if defined HAVE_MPFR && defined WITH_MPFR
1100 ent_binop_register(ASE_BINARY_OP_QUO,
1101 BIGG_T, BIGFR_T, ent_div_BIGG_T_COMPARABLE);
1102 ent_binop_register(ASE_BINARY_OP_QUO,
1103 BIGFR_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1106 ent_binop_register(ASE_BINARY_OP_QUO,
1107 BIGG_T, FLOAT_T, ent_div_BIGG_T_COMPARABLE);
1108 ent_binop_register(ASE_BINARY_OP_QUO,
1109 FLOAT_T, BIGG_T, ent_div_COMPARABLE_BIGG_T);
1112 ent_binop_register(ASE_BINARY_OP_REM,
1113 BIGG_T, BIGG_T, ent_rem_BIGG_T);
1114 ent_binop_register(ASE_BINARY_OP_MOD,
1115 BIGG_T, BIGG_T, ent_rem_BIGG_T);
1116 ent_binop_register(ASE_BINARY_OP_POW,
1117 BIGG_T, INT_T, ent_pow_BIGG_T_integer);
1118 ent_binop_register(ASE_BINARY_OP_POW,
1119 BIGG_T, BIGZ_T, ent_pow_BIGG_T_integer);
1123 ent_gaussian_unary_reltable_init(void)
1125 ent_unrel_register(ASE_UNARY_REL_ZEROP, BIGG_T, ent_gaussian_zerop);
1126 ent_unrel_register(ASE_UNARY_REL_ONEP, BIGG_T, ent_gaussian_onep);
1127 ent_unrel_register(ASE_UNARY_REL_UNITP, BIGG_T, ent_gaussian_unitp);
1131 ent_gaussian_binary_reltable_init(void)
1133 ent_binrel_register(ASE_BINARY_REL_EQUALP,
1134 BIGG_T, BIGG_T, ent_eq_bigg);
1135 ent_binrel_register(ASE_BINARY_REL_NEQP,
1136 BIGG_T, BIGG_T, ent_ne_bigg);
1140 ent_gaussian_lifttable_init(void)
1142 ent_lift_register(INT_T, BIGG_T, ent_lift_all_BIGG_T);
1143 ent_lift_register(BIGZ_T, BIGC_T, ent_lift_all_BIGG_T);
1144 #if defined HAVE_MPQ && defined WITH_GMP
1145 ent_lift_register(BIGQ_T, BIGG_T, ent_lift_all_BIGG_T);
1147 #if defined HAVE_MPF && defined WITH_GMP
1148 ent_lift_register(BIGF_T, BIGG_T, ent_lift_all_BIGG_T);
1150 #if defined HAVE_MPFR && defined WITH_MPFR
1151 ent_lift_register(BIGFR_T, BIGG_T, ent_lift_all_BIGG_T);
1154 ent_lift_register(FLOAT_T, BIGG_T, ent_lift_all_BIGG_T);
1156 #if defined HAVE_MPC && defined WITH_MPC || \
1157 defined HAVE_PSEUC && defined WITH_PSEUC
1158 ent_lift_register(BIGC_T, BIGG_T, ent_lift_BIGC_T_BIGG_T);
1162 void init_optables_BIGG_T(void)
1164 ent_gaussian_nullary_optable_init();
1165 ent_gaussian_unary_optable_init();
1166 ent_gaussian_binary_optable_init();
1167 ent_gaussian_unary_reltable_init();
1168 ent_gaussian_binary_reltable_init();
1169 ent_gaussian_lifttable_init();
1172 void init_ent_gaussian(void)
1174 bigg_init(ent_scratch_bigg);
1177 void syms_of_ent_gaussian(void)
1179 INIT_LRECORD_IMPLEMENTATION(bigg);
1181 DEFSUBR(Fmake_bigg);
1184 void vars_of_ent_gaussian(void)
1186 Fprovide(intern("bigg"));
1187 Fprovide(intern("gaussian"));