Mercurial > hg > xemacs-beta
annotate src/number-mp.h @ 5894:23178aa71f8b
Define ALIGNOF using C11 and C++11 operators.
See <CAHCOHQmG51R61KwGUNY7T5t9tXxzbyg=aGijUKYstbE+wL2-6Q@mail.gmail.com> in
xemacs-patches for more information.
author | Jerry James <james@xemacs.org> |
---|---|
date | Mon, 20 Apr 2015 15:09:11 -0600 |
parents | 3192994c49ca |
children |
rev | line source |
---|---|
1983 | 1 /* Definitions of numeric types for XEmacs using the 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 = MINT | |
23 | |
24 The MP library does not include support for ratios or bigfloats. | |
25 */ | |
26 | |
27 #ifndef INCLUDED_number_mp_h_ | |
28 #define INCLUDED_number_mp_h_ | |
29 | |
30 /* BSD MP libraries without MP_PREFIX define a function named pow in mp.h that | |
31 has a different prototype from the one in math.h. We don't use that | |
32 function anyway, so we do this for safety purposes. However, this means | |
33 that number-mp.h must always be included before math.h. */ | |
34 #define pow mp_pow | |
5602
c9e5612f5424
Support the MP library on recent FreeBSD, have it pass relevant tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5405
diff
changeset
|
35 BEGIN_C_DECLS |
1983 | 36 #include <mp.h> |
5602
c9e5612f5424
Support the MP library on recent FreeBSD, have it pass relevant tests.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5405
diff
changeset
|
37 END_C_DECLS |
1983 | 38 #undef pow |
39 | |
40 #ifdef MP_PREFIX | |
41 #define MP_GCD mp_gcd | |
42 #define MP_ITOM mp_itom | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
43 #define MP_XTOM mp_xtom |
1983 | 44 #define MP_MADD mp_madd |
45 #define MP_MCMP mp_mcmp | |
46 #define MP_MDIV mp_mdiv | |
47 #define MP_MFREE mp_mfree | |
48 #define MP_MSUB mp_msub | |
49 #define MP_MULT mp_mult | |
50 #define MP_SDIV mp_sdiv | |
51 #ifdef HAVE_MP_MOVE | |
52 #define MP_MOVE(x,y) mp_move (x, y) | |
53 #else | |
54 #define MP_MOVE(x,y) mp_madd (x, bignum_zero, y) | |
55 #endif | |
56 #else | |
57 #define MP_GCD gcd | |
58 #define MP_ITOM itom | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
59 #define MP_XTOM xtom |
1983 | 60 #define MP_MADD madd |
61 #define MP_MCMP mcmp | |
62 #define MP_MDIV mdiv | |
63 #define MP_MFREE mfree | |
64 #define MP_MSUB msub | |
65 #define MP_MULT mult | |
66 #define MP_SDIV sdiv | |
67 #ifdef HAVE_MP_MOVE | |
68 #define MP_MOVE(x,y) move (x, y) | |
69 #else | |
70 #define MP_MOVE(x,y) madd (x, bignum_zero, y) | |
71 #endif | |
72 #endif | |
73 | |
74 typedef MINT *bignum; | |
75 | |
76 extern void init_number_mp(void); | |
77 | |
78 | |
79 /********************************* Bignums **********************************/ | |
80 | |
81 #define HAVE_BIGNUM 1 | |
82 | |
83 extern MINT *bignum_zero, *intern_bignum; | |
84 extern MINT *bignum_min_int, *bignum_max_int, *bignum_max_uint; | |
85 extern MINT *bignum_min_long, *bignum_max_long, *bignum_max_ulong; | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
86 extern MINT *bignum_min_llong, *bignum_max_llong, *bignum_max_ullong; |
1983 | 87 extern short div_rem; |
88 | |
89 /***** Bignum: basic functions *****/ | |
90 #define bignum_init(b) (b = MP_ITOM (0)) | |
91 #define bignum_fini(b) MP_MFREE (b) | |
92 #define bignum_hashcode(b) bignum_to_uint (b) | |
93 #define bignum_sign(b) MP_MCMP (b, bignum_zero) | |
94 #define bignum_evenp(b) (MP_SDIV (b, 2, intern_bignum, &div_rem), \ | |
95 div_rem == 0) | |
96 #define bignum_oddp(b) (MP_SDIV (b, 2, intern_bignum, &div_rem), \ | |
97 div_rem != 0) | |
98 | |
99 /***** Bignum: size *****/ | |
100 #define bignum_fits_int_p(b) (MP_MCMP (b, bignum_min_int) >= 0 && \ | |
101 MP_MCMP (b, bignum_max_int) <= 0) | |
102 #define bignum_fits_uint_p(b) (MP_MCMP (b, bignum_zero) >= 0 && \ | |
103 MP_MCMP (b, bignum_max_uint) <= 0) | |
104 #define bignum_fits_long_p(b) (MP_MCMP (b, bignum_min_long) >= 0 && \ | |
105 MP_MCMP (b, bignum_max_long) <= 0) | |
106 #define bignum_fits_ulong_p(b) (MP_MCMP (b, bignum_zero) >= 0 && \ | |
107 MP_MCMP (b, bignum_max_ulong) <= 0) | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
108 #define bignum_fits_llong_p(b) (MP_MCMP (b, bignum_min_llong) >= 0 && \ |
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
109 MP_MCMP (b, bignum_max_llong) <= 0) |
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
110 #define bignum_fits_ullong_p(b) (MP_MCMP (b, bignum_zero) >= 0 && \ |
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
111 MP_MCMP (b, bignum_max_ullong) <= 0) |
1983 | 112 |
113 /***** Bignum: conversions *****/ | |
114 extern char *bignum_to_string(bignum, int); | |
115 extern int bignum_to_int(bignum); | |
116 extern unsigned int bignum_to_uint(bignum); | |
117 extern long bignum_to_long(bignum); | |
118 extern unsigned long bignum_to_ulong(bignum); | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
119 extern long long bignum_to_llong(bignum); |
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
120 extern unsigned long long bignum_to_ullong(bignum); |
1983 | 121 extern double bignum_to_double(bignum); |
122 | |
123 /***** Bignum: converting assignments *****/ | |
124 #define bignum_set(b1, b2) MP_MOVE (b2, b1) | |
125 extern int bignum_set_string(bignum, const char *, int); | |
126 extern void bignum_set_long(bignum, long); | |
127 extern void bignum_set_ulong(bignum, unsigned long); | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
128 extern void bignum_set_llong(bignum, long long); |
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
129 extern void bignum_set_ullong(bignum, unsigned long long); |
1983 | 130 extern void bignum_set_double(bignum, double); |
131 | |
132 /***** Bignum: comparisons *****/ | |
133 #define bignum_cmp(b1,b2) MP_MCMP (b1, b2) | |
134 #define bignum_lt(b1,b2) (MP_MCMP (b1, b2) < 0) | |
135 #define bignum_le(b1,b2) (MP_MCMP (b1, b2) <= 0) | |
136 #define bignum_eql(b1,b2) (MP_MCMP (b1, b2) == 0) | |
137 #define bignum_ge(b1,b2) (MP_MCMP (b1, b2) >= 0) | |
138 #define bignum_gt(b1,b2) (MP_MCMP (b1, b2) > 0) | |
139 | |
140 /***** Bignum: arithmetic *****/ | |
141 #define bignum_neg(b,b2) MP_MSUB (bignum_zero, b2, b) | |
142 #define bignum_abs(b,b2) (MP_MCMP (b2, bignum_zero) < 0 \ | |
143 ? MP_MSUB (bignum_zero, b2, b) \ | |
144 : MP_MADD (bignum_zero, b2, b)) | |
145 #define bignum_add(b,b1,b2) MP_MADD (b1, b2, b) | |
146 #define bignum_sub(b,b1,b2) MP_MSUB (b1, b2, b) | |
147 #define bignum_mul(b,b1,b2) MP_MULT (b1, b2, b) | |
148 extern int bignum_divisible_p(bignum, bignum); | |
149 #define bignum_div(b,b1,b2) MP_MDIV (b1, b2, b, intern_bignum) | |
150 extern void bignum_ceil(bignum, bignum, bignum); | |
151 extern void bignum_floor(bignum, bignum, bignum); | |
152 #define bignum_mod(b,b1,b2) MP_MDIV (b1, b2, intern_bignum, b) | |
153 extern void bignum_pow(bignum, bignum, unsigned long); | |
154 #define bignum_gcd(res,b1,b2) MP_GCD (b1, b2, res) | |
155 extern void bignum_lcm(bignum, bignum, bignum); | |
156 | |
157 /***** Bignum: bit manipulations *****/ | |
158 extern void bignum_and(bignum, bignum, bignum); | |
159 extern void bignum_ior(bignum, bignum, bignum); | |
160 extern void bignum_xor(bignum, bignum, bignum); | |
161 extern void bignum_not(bignum, bignum); | |
162 extern void bignum_setbit(bignum, unsigned long); | |
163 extern void bignum_clrbit(bignum, unsigned long); | |
164 extern int bignum_testbit(bignum, unsigned long); | |
165 extern void bignum_lshift(bignum, bignum, unsigned long); | |
166 extern void bignum_rshift(bignum, bignum, unsigned long); | |
167 | |
168 /***** Bignum: random numbers *****/ | |
5736
3192994c49ca
Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents:
5602
diff
changeset
|
169 #define bignum_random_seed(s) |
1983 | 170 extern void bignum_random(bignum, bignum); |
171 | |
172 #endif /* INCLUDED_number_mp_h_ */ |