Mercurial > hg > xemacs-beta
annotate src/number-gmp.h @ 5561:9a93bc90b3bd
Add a defsetf for get-char-table, necessary for the tests in the last commit.
lisp/ChangeLog addition:
2011-09-04 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (get-char-table): Add a defsetf for this.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sun, 04 Sep 2011 20:35:31 +0100 |
| parents | 2aa9cd456ae7 |
| children | 3192994c49ca |
| rev | line source |
|---|---|
| 1983 | 1 /* Definitions of numeric types for XEmacs using the GNU MP library. |
| 2 Copyright (C) 2004 Jerry James. | |
| 3 | |
| 4 This file is part of XEmacs. | |
| 5 | |
|
5405
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5231
diff
changeset
|
6 XEmacs is free software: you can redistribute it and/or modify it |
| 1983 | 7 under the terms of the GNU General Public License as published by the |
|
5405
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5231
diff
changeset
|
8 Free Software Foundation, either version 3 of the License, or (at your |
|
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5231
diff
changeset
|
9 option) any later version. |
| 1983 | 10 |
| 11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
|
5405
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
5231
diff
changeset
|
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 1983 | 18 |
| 19 /* Synched up with: Not in FSF. */ | |
| 20 | |
| 21 /* This library defines the following types: | |
| 22 bignum = mpz_t | |
| 23 ratio = mpq_t | |
| 24 bigfloat = mpf_t | |
| 25 */ | |
| 26 | |
| 27 #ifndef INCLUDED_number_gmp_h_ | |
| 28 #define INCLUDED_number_gmp_h_ | |
| 29 | |
| 2286 | 30 #ifdef UNO |
| 31 /* Uno complains about several inline functions that include conditions with | |
| 32 assignments and side effects if we don't do this */ | |
| 33 #undef __GNUC__ | |
| 34 #endif | |
| 35 | |
| 2956 | 36 #ifdef _MSC_VER |
| 37 /* "unary minus operator applied to unsigned type, result still unsigned": | |
| 38 Occurs on line 1596 of gmp.h in version 4.1.4. */ | |
| 39 #pragma warning ( disable : 4146 ) | |
| 40 #endif | |
| 1983 | 41 #include <gmp.h> |
| 2956 | 42 #ifdef _MSC_VER |
| 43 #pragma warning ( default : 4146 ) | |
| 44 #endif | |
| 1983 | 45 |
| 46 typedef mpz_t bignum; | |
| 47 typedef mpq_t ratio; | |
| 48 typedef mpf_t bigfloat; | |
| 49 | |
| 50 extern void init_number_gmp(void); | |
| 51 | |
| 52 | |
| 53 /********************************* Bignums **********************************/ | |
| 54 | |
| 55 #define HAVE_BIGNUM 1 | |
| 56 | |
| 57 extern gmp_randstate_t random_state; | |
| 58 | |
| 59 /***** Bignum: basic functions *****/ | |
| 60 #define bignum_init(b) mpz_init (b) | |
| 61 #define bignum_fini(b) mpz_clear (b) | |
| 62 #define bignum_hashcode(b) mpz_get_ui (b) | |
| 63 #define bignum_sign(b) mpz_sgn (b) | |
| 64 #define bignum_evenp(b) mpz_even_p (b) | |
| 65 #define bignum_oddp(b) mpz_odd_p (b) | |
| 66 | |
| 67 /***** Bignum: size *****/ | |
| 68 #define bignum_fits_int_p(b) mpz_fits_sint_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) | |
| 71 #define bignum_fits_ulong_p(b) mpz_fits_ulong_p (b) | |
| 72 | |
| 73 /***** Bignum: conversions *****/ | |
| 74 #define bignum_to_string(b,base) mpz_get_str (NULL, base, b) | |
| 75 #define bignum_to_int(b) ((int) mpz_get_si (b)) | |
| 76 #define bignum_to_uint(b) ((unsigned int) mpz_get_ui (b)) | |
| 77 #define bignum_to_long(b) mpz_get_si (b) | |
| 78 #define bignum_to_ulong(b) mpz_get_ui (b) | |
| 79 #define bignum_to_double(b) mpz_get_d (b) | |
| 80 | |
| 81 /***** Bignum: converting assignments *****/ | |
| 82 #define bignum_set(b1,b2) mpz_set (b1, b2) | |
| 83 #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) | |
| 85 #define bignum_set_ulong(b,l) mpz_set_ui (b, l) | |
| 86 #define bignum_set_double(b,f) mpz_set_d (b, f) | |
| 87 #define bignum_set_ratio(b,r) mpz_set_q (b, r) | |
| 88 #define bignum_set_bigfloat(b,f) mpz_set_f (b, f) | |
| 89 | |
| 90 /***** Bignum: comparisons *****/ | |
| 91 #define bignum_cmp(b1,b2) mpz_cmp (b1, b2) | |
| 92 #define bignum_lt(b1,b2) (mpz_cmp (b1, b2) < 0) | |
| 93 #define bignum_le(b1,b2) (mpz_cmp (b1, b2) <= 0) | |
| 94 #define bignum_eql(b1,b2) (mpz_cmp (b1, b2) == 0) | |
| 95 #define bignum_ge(b1,b2) (mpz_cmp (b1, b2) >= 0) | |
| 96 #define bignum_gt(b1,b2) (mpz_cmp (b1, b2) > 0) | |
| 97 | |
| 98 /***** Bignum: arithmetic *****/ | |
| 99 #define bignum_neg(b,b2) mpz_neg (b, b2) | |
| 100 #define bignum_abs(b,b2) mpz_abs (b, b2) | |
| 101 #define bignum_add(b,b1,b2) mpz_add (b, b1, b2) | |
| 102 #define bignum_sub(b,b1,b2) mpz_sub (b, b1, b2) | |
| 103 #define bignum_mul(b,b1,b2) mpz_mul (b, b1, b2) | |
| 104 #define bignum_divisible_p(b1,b2) mpz_divisible_p (b1, b2) | |
| 105 #define bignum_div(b,b1,b2) mpz_tdiv_q (b, b1, b2) | |
| 106 #define bignum_ceil(b,b1,b2) mpz_cdiv_q (b, b1, b2) | |
| 107 #define bignum_floor(b,b1,b2) mpz_fdiv_q (b, b1, b2) | |
| 108 #define bignum_mod(b,b1,b2) mpz_mod (b, b1, b2) | |
| 109 #define bignum_pow(res,b,pow) mpz_pow_ui (res, b, pow) | |
| 110 #define bignum_gcd(res,b1,b2) mpz_gcd (res, b1, b2) | |
| 111 #define bignum_lcm(res,b1,b2) mpz_lcm (res, b1, b2) | |
| 112 | |
| 113 /***** Bignum: bit manipulations *****/ | |
| 114 #define bignum_and(res,b1,b2) mpz_and (res, b1, b2) | |
| 115 #define bignum_ior(res,b1,b2) mpz_ior (res, b1, b2) | |
| 116 #define bignum_xor(res,b1,b2) mpz_xor (res, b1, b2) | |
| 117 #define bignum_not(res,b) mpz_com (res, b) | |
| 118 #define bignum_setbit(b,bit) mpz_setbit (b, bit) | |
| 119 #define bignum_clrbit(b,bit) mpz_clrbit (b, bit) | |
| 120 #define bignum_testbit(b,bit) mpz_tstbit (b, bit) | |
| 121 #define bignum_lshift(res,b,bits) mpz_mul_2exp (res, b, bits) | |
| 122 #define bignum_rshift(res,b,bits) mpz_fdiv_q_2exp (res, b, bits) | |
| 123 | |
| 124 /***** Bignum: random numbers *****/ | |
| 125 #define bignum_random_seed(seed) gmp_randseed_ui (random_state, seed) | |
| 126 #define bignum_random(res,limit) mpz_urandomm (res, random_state, limit) | |
| 127 | |
| 128 | |
| 129 /********************************** Ratios **********************************/ | |
| 130 | |
| 131 #define HAVE_RATIO 1 | |
| 132 | |
| 133 /***** Ratio: basic functions *****/ | |
| 134 #define ratio_init(r) mpq_init (r) | |
| 135 #define ratio_fini(r) mpq_clear (r) | |
| 136 #define ratio_hashcode(r) \ | |
| 137 (mpz_get_ui (mpq_denref (r)) * mpz_get_ui (mpq_numref (r))) | |
| 138 #define ratio_sign(r) mpq_sgn (r) | |
| 139 #define ratio_numerator(r) mpq_numref (r) | |
| 140 #define ratio_denominator(r) mpq_denref (r) | |
| 141 #define ratio_canonicalize(r) mpq_canonicalize (r) | |
| 142 | |
| 143 /***** Ratio: conversions *****/ | |
| 144 #define ratio_to_string(r,base) mpq_get_str (NULL, base, r) | |
| 145 #define ratio_to_int(r) ((int) (mpq_get_d (r))) | |
| 146 #define ratio_to_uint(r) ((unsigned int) (mpq_get_d (r))) | |
| 147 #define ratio_to_long(r) ((long) (mpq_get_d (r))) | |
| 148 #define ratio_to_ulong(r) ((unsigned long) (mpq_get_d (r))) | |
| 149 #define ratio_to_double(r) mpq_get_d (r) | |
| 150 | |
| 151 /***** Ratio: converting assignments *****/ | |
| 152 #define ratio_set(r1,r2) mpq_set (r1, r2) | |
| 153 #define ratio_set_string(r,s,base) mpq_set_str (r, s, base) | |
| 154 #define ratio_set_long(r,l) mpq_set_si (r, l, 1UL) | |
| 155 #define ratio_set_ulong(r,l) mpq_set_ui (r, l, 1UL) | |
| 156 #define ratio_set_double(r,f) mpq_set_d (r, f) | |
| 157 #define ratio_set_bignum(r,b) mpq_set_z (r, b) | |
| 158 #define ratio_set_bigfloat(r,f) mpq_set_f (r, f) | |
| 159 #define ratio_set_long_ulong(r,num,den) mpq_set_si (r, num, den) | |
| 160 #define ratio_set_ulong_ulong(r,num,den) mpq_set_ui (r, num, den) | |
| 2551 | 161 /* FIXME: Why does this canonicalize, but the previous 2 don't? */ |
| 1983 | 162 #define ratio_set_bignum_bignum(r,num,den) do { \ |
| 163 mpz_set (mpq_numref (r), num); \ | |
| 164 mpz_set (mpq_denref (r), den); \ | |
| 165 mpq_canonicalize (r); \ | |
| 166 } while (0) | |
| 167 | |
| 168 /***** Ratio: comparisons *****/ | |
| 169 #define ratio_cmp(r1,r2) mpq_cmp (r1, r2) | |
| 170 #define ratio_lt(r1,r2) (mpq_cmp (r1, r2) < 0) | |
| 171 #define ratio_le(r1,r2) (mpq_cmp (r1, r2) <= 0) | |
| 172 #define ratio_eql(r1,r2) mpq_equal (r1, r2) | |
| 173 #define ratio_ge(r1,r2) (mpq_cmp (r1, r2) >= 0) | |
| 174 #define ratio_gt(r1,r2) (mpq_cmp (r1, r2) > 0) | |
| 175 | |
| 176 /***** Ratio: arithmetic *****/ | |
| 177 #define ratio_neg(q,q2) mpq_neg (q, q2) | |
| 178 #define ratio_abs(q,q2) mpq_abs (q, q2) | |
| 179 #define ratio_inv(q,q2) mpq_inv (q, q2) | |
| 180 #define ratio_add(res,q1,q2) mpq_add (res, q1, q2) | |
| 181 #define ratio_sub(res,q1,q2) mpq_sub (res, q1, q2) | |
| 182 #define ratio_mul(res,q1,q2) mpq_mul (res, q1, q2) | |
| 183 #define ratio_div(res,q1,q2) mpq_div (res, q1, q2) | |
| 184 | |
| 185 | |
| 186 /******************************** Bigfloats *********************************/ | |
| 187 | |
| 188 #define HAVE_BIGFLOAT 1 | |
| 189 | |
| 190 /***** Bigfloat: basic functions *****/ | |
| 191 #define bigfloat_init(f) mpf_init (f) | |
| 192 #define bigfloat_init_prec(f,prec) mpf_init2 (f, prec) | |
| 193 #define bigfloat_fini(f) mpf_clear (f) | |
| 194 #define bigfloat_hashcode(f) mpf_get_ui (f) | |
| 195 #define bigfloat_sign(f) mpf_sgn (f) | |
| 196 #define bigfloat_get_prec(f) mpf_get_prec (f) | |
| 197 #define bigfloat_set_prec(f, prec) mpf_set_prec (f, prec) | |
| 198 #define bigfloat_set_default_prec(prec) mpf_set_default_prec(prec) | |
| 199 #define bigfloat_get_default_prec() mpf_get_default_prec () | |
| 200 | |
| 201 /***** Bigfloat: conversions *****/ | |
| 202 extern CIbyte *bigfloat_to_string (bigfloat f, int base); | |
| 203 #define bigfloat_to_int(f) ((int) mpf_get_si (f)) | |
| 204 #define bigfloat_to_uint(f) ((unsigned int) mpf_get_ui (f)) | |
| 205 #define bigfloat_to_long(f) mpf_get_si (f) | |
| 206 #define bigfloat_to_ulong(f) mpf_get_ui (f) | |
| 207 #define bigfloat_to_double(f) mpf_get_d (f) | |
| 208 | |
| 209 /***** Bigfloat: converting assignments *****/ | |
| 210 #define bigfloat_set(f1,f2) mpf_set (f1, f2) | |
| 211 #define bigfloat_set_string(f,str,base) mpf_set_str (f, str, base) | |
| 212 #define bigfloat_set_long(f,l) mpf_set_si (f, l) | |
| 213 #define bigfloat_set_ulong(f,l) mpf_set_ui (f, l) | |
| 214 #define bigfloat_set_double(d,f) mpf_set_d (d, f) | |
| 215 #define bigfloat_set_bignum(f,b) mpf_set_z (f, b) | |
| 216 #define bigfloat_set_ratio(f,r) mpf_set_q (f, r) | |
| 217 | |
| 218 /***** Bigfloat: comparisons *****/ | |
| 219 #define bigfloat_cmp(f1,f2) mpf_cmp (f1, f2) | |
| 220 #define bigfloat_lt(f1,f2) (mpf_cmp (f1, f2) < 0) | |
| 221 #define bigfloat_le(f1,f2) (mpf_cmp (f1, f2) <= 0) | |
| 222 #define bigfloat_eql(f1,f2) (mpf_cmp (f1, f2) == 0) | |
| 223 #define bigfloat_eql_bits(f1,f2,bits) mpf_eq (f1, f2, bits) | |
| 224 #define bigfloat_ge(f1,f2) (mpf_cmp (f1, f2) >= 0) | |
| 225 #define bigfloat_gt(f1,f2) (mpf_cmp (f1, f2) > 0) | |
| 226 | |
| 227 /***** Bigfloat: arithmetic *****/ | |
| 228 #define bigfloat_neg(f,f2) mpf_neg (f, f2) | |
| 229 #define bigfloat_abs(f,f2) mpf_abs (f, f2) | |
| 230 #define bigfloat_add(res,f1,f2) mpf_add (res, f1, f2) | |
| 231 #define bigfloat_sub(res,f1,f2) mpf_sub (res, f1, f2) | |
| 232 #define bigfloat_mul(res,f1,f2) mpf_mul (res, f1, f2) | |
| 233 #define bigfloat_div(res,f1,f2) mpf_div (res, f1, f2) | |
| 234 #define bigfloat_ceil(res,f) mpf_ceil (res, f) | |
| 235 #define bigfloat_floor(res,f) mpf_floor (res, f) | |
| 236 #define bigfloat_trunc(res,f) mpf_trunc (res, f) | |
| 237 #define bigfloat_sqrt(res,f) mpf_sqrt (res, f) | |
| 238 #define bigfloat_pow(res,f,exp) mpf_pow_ui (res, f, exp) | |
| 239 | |
| 240 #endif /* INCLUDED_number_gmp_h_ */ |
