comparison src/number-gmp.h @ 5736:3192994c49ca

Convert C (un)signed long long values to bignums properly. This patch also does the following: - Uses make_fixnum instead of make_integer when the argument is guaranteed to be in the fixnum range. - Introduces make_unsigned_integer so that we handle unsigned values with the high bit set correctly. - Introduces conversions between bignums and (un)signed long long values. - Uses mp_set_memory_functions with the BSD MP code, if it exists. - Eliminates some unnecessary consing in the Lisp + and * implementations. - Fixes a problem with check_valid_xbm_inline(). This function is called during intialization. It calls Ftimes. When using pdump, this is a problem, because (a) the bignum code is not initialized until *after* dumping, so we don't try to dump any bignums, and (b) multiplication of integers is done inside bignums so we handle fixnum overflow correctly. I decided that an XBM file with dimensions that don't fit into fixnums is probably not something we want to try to handle anyway, and did the arithmetic with C values instead of Lisp values. Doing that broke one test, which started getting a different error message from the one it expected, so I adjusted the test to match the new reality. - Fixes a few miscellaneous bugs in the BSD MP code. See <CAHCOHQk0u0=eD1fUMHTNWi2Yh=1WgiYyCXdMbsGzHBNhdqYz4w@mail.gmail.com> in xemacs-patches, as well as followup messages.
author Jerry James <james@xemacs.org>
date Mon, 17 Jun 2013 10:23:00 -0600
parents 2aa9cd456ae7
children a2912073be85
comparison
equal deleted inserted replaced
5735:ff13c44ce0d9 5736:3192994c49ca
67 /***** Bignum: size *****/ 67 /***** Bignum: size *****/
68 #define bignum_fits_int_p(b) mpz_fits_sint_p (b) 68 #define bignum_fits_int_p(b) mpz_fits_sint_p (b)
69 #define bignum_fits_uint_p(b) mpz_fits_uint_p (b) 69 #define bignum_fits_uint_p(b) mpz_fits_uint_p (b)
70 #define bignum_fits_long_p(b) mpz_fits_slong_p (b) 70 #define bignum_fits_long_p(b) mpz_fits_slong_p (b)
71 #define bignum_fits_ulong_p(b) mpz_fits_ulong_p (b) 71 #define bignum_fits_ulong_p(b) mpz_fits_ulong_p (b)
72 #define bignum_fits_llong_p(b) \
73 (mpz_sizeinbase (b, 2) <= (sizeof(long long) << 3) - 1U)
74 #define bignum_fits_ullong_p(b) \
75 (mpz_sgn (b) >= 0 && \
76 mpz_sizeinbase (b, 2) <= (sizeof(unsigned long long) << 3))
72 77
73 /***** Bignum: conversions *****/ 78 /***** Bignum: conversions *****/
74 #define bignum_to_string(b,base) mpz_get_str (NULL, base, b) 79 #define bignum_to_string(b,base) mpz_get_str (NULL, base, b)
75 #define bignum_to_int(b) ((int) mpz_get_si (b)) 80 #define bignum_to_int(b) ((int) mpz_get_si (b))
76 #define bignum_to_uint(b) ((unsigned int) mpz_get_ui (b)) 81 #define bignum_to_uint(b) ((unsigned int) mpz_get_ui (b))
77 #define bignum_to_long(b) mpz_get_si (b) 82 #define bignum_to_long(b) mpz_get_si (b)
78 #define bignum_to_ulong(b) mpz_get_ui (b) 83 #define bignum_to_ulong(b) mpz_get_ui (b)
84 extern long long bignum_to_llong(const bignum b);
85 extern unsigned long long bignum_to_ullong(const bignum b);
79 #define bignum_to_double(b) mpz_get_d (b) 86 #define bignum_to_double(b) mpz_get_d (b)
80 87
81 /***** Bignum: converting assignments *****/ 88 /***** Bignum: converting assignments *****/
82 #define bignum_set(b1,b2) mpz_set (b1, b2) 89 #define bignum_set(b1,b2) mpz_set (b1, b2)
83 #define bignum_set_string(b,s,base) mpz_set_str (b, s, base) 90 #define bignum_set_string(b,s,base) mpz_set_str (b, s, base)
84 #define bignum_set_long(b,l) mpz_set_si (b, l) 91 #define bignum_set_long(b,l) mpz_set_si (b, l)
85 #define bignum_set_ulong(b,l) mpz_set_ui (b, l) 92 #define bignum_set_ulong(b,l) mpz_set_ui (b, l)
93 extern void bignum_set_llong(bignum b, long long l);
94 #define bignum_set_ullong(b,l) mpz_import (b,1U,1,sizeof (l),0,0U,&l)
86 #define bignum_set_double(b,f) mpz_set_d (b, f) 95 #define bignum_set_double(b,f) mpz_set_d (b, f)
87 #define bignum_set_ratio(b,r) mpz_set_q (b, r) 96 #define bignum_set_ratio(b,r) mpz_set_q (b, r)
88 #define bignum_set_bigfloat(b,f) mpz_set_f (b, f) 97 #define bignum_set_bigfloat(b,f) mpz_set_f (b, f)
89 98
90 /***** Bignum: comparisons *****/ 99 /***** Bignum: comparisons *****/