[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / includes / gmp.h
1 /* gmp.h -- Definitions for GNU multiple precision functions.
2
3 Copyright (C) 1991, 1993 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library.
6
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 The GNU MP Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with the GNU MP Library; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 #ifndef __GMP_H__
22 #define __GMP_H__
23
24 #define __GNU_MP__
25
26 #ifndef __MP_H__
27 #define __need_size_t
28 #include <stddef.h>
29 #endif
30
31 #ifndef MINT
32 #ifndef __MP_SMALL__
33 typedef struct
34 {
35   long int alloc;               /* Number of *limbs* allocated and pointed
36                                    to by the D field.  */
37   long int size;                /* abs(SIZE) is the number of limbs
38                                    the last field points to.  If SIZE
39                                    is negative this is a negative
40                                    number.  */
41   unsigned long int *d;         /* Pointer to the limbs.  */
42 } __MP_INT;
43 #else
44 typedef struct
45 {
46   short int alloc;              /* Number of *limbs* allocated and pointed
47                                    to by the D field.  */
48   short int size;               /* abs(SIZE) is the number of limbs
49                                    the last field points to.  If SIZE
50                                    is negative this is a negative
51                                    number.  */
52   unsigned long int *d;         /* Pointer to the limbs.  */
53 } __MP_INT;
54 #endif
55 #endif
56
57 #define MP_INT __MP_INT
58
59 typedef unsigned long int       mp_limb;
60 typedef long int                mp_limb_signed;
61 typedef mp_limb *               mp_ptr;
62 #ifdef __STDC__
63 typedef const mp_limb *         mp_srcptr;
64 #else
65 typedef mp_limb *               mp_srcptr;
66 #endif
67 typedef long int                mp_size;
68
69 /* Structure for rational numbers.  Zero is represented as 0/any, i.e.
70    the denominator is ignored.  Negative numbers have the sign in
71    the numerator.  */
72 typedef struct
73 {
74   MP_INT num;
75   MP_INT den;
76 #if 0
77   long int num_alloc;           /* Number of limbs allocated
78                                    for the numerator.  */
79   long int num_size;            /* The absolute value of this field is the
80                                    length of the numerator; the sign is the
81                                    sign of the entire rational number.  */
82   mp_ptr num;                   /* Pointer to the numerator limbs.  */
83   long int den_alloc;           /* Number of limbs allocated
84                                    for the denominator.  */
85   long int den_size;            /* Length of the denominator.  (This field
86                                    should always be positive.) */
87   mp_ptr den;                   /* Pointer to the denominator limbs.  */
88 #endif
89 } MP_RAT;
90
91 #ifdef __STDC__
92 void mp_set_memory_functions (void *(*) (size_t),
93                               void *(*) (void *, size_t, size_t),
94                               void (*) (void *, size_t));
95
96 /**************** Integer (i.e. Z) routines.  ****************/
97
98 void mpz_init (MP_INT *);
99 void mpz_set (MP_INT *, const MP_INT *);
100 void mpz_set_ui (MP_INT *, unsigned long int);
101 void mpz_set_si (MP_INT *, signed long int);
102 int mpz_set_str (MP_INT *, const char *, int);
103 void mpz_init_set (MP_INT *, const MP_INT *);
104 void mpz_init_set_ui (MP_INT *, unsigned long int);
105 void mpz_init_set_si (MP_INT *, signed long int);
106 int mpz_init_set_str (MP_INT *, const char *, int);
107 unsigned long int mpz_get_ui (const MP_INT *);
108 signed long int mpz_get_si (const MP_INT *);
109 char * mpz_get_str (char *, int, const MP_INT *);
110 void mpz_clear (MP_INT *);
111 void * _mpz_realloc (MP_INT *, mp_size);
112 void mpz_add (MP_INT *, const MP_INT *, const MP_INT *);
113 void mpz_add_ui (MP_INT *, const MP_INT *, unsigned long int);
114 void mpz_sub (MP_INT *, const MP_INT *, const MP_INT *);
115 void mpz_sub_ui (MP_INT *, const MP_INT *, unsigned long int);
116 void mpz_mul (MP_INT *, const MP_INT *, const MP_INT *);
117 void mpz_mul_ui (MP_INT *, const MP_INT *, unsigned long int);
118 void mpz_div (MP_INT *, const MP_INT *, const MP_INT *);
119 void mpz_div_ui (MP_INT *, const MP_INT *, unsigned long int);
120 void mpz_mod (MP_INT *, const MP_INT *, const MP_INT *);
121 void mpz_mod_ui (MP_INT *, const MP_INT *, unsigned long int);
122 void mpz_divmod (MP_INT *, MP_INT *, const MP_INT *, const MP_INT *);
123 void mpz_divmod_ui (MP_INT *, MP_INT *, const MP_INT *, unsigned long int);
124 void mpz_mdiv (MP_INT *, const MP_INT *, const MP_INT *);
125 void mpz_mdiv_ui (MP_INT *, const MP_INT *, unsigned long int);
126 void mpz_mmod (MP_INT *, const MP_INT *, const MP_INT *);
127 unsigned long int mpz_mmod_ui (MP_INT *, const MP_INT *, unsigned long int);
128 void mpz_mdivmod (MP_INT *, MP_INT *, const MP_INT *, const MP_INT *);
129 unsigned long int mpz_mdivmod_ui (MP_INT *, MP_INT *, const MP_INT *,
130                                   unsigned long int);
131 void mpz_sqrt (MP_INT *, const MP_INT *);
132 void mpz_sqrtrem (MP_INT *, MP_INT *, const MP_INT *);
133 int mpz_perfect_square_p (const MP_INT *);
134 int mpz_probab_prime_p (const MP_INT *, int);
135 void mpz_powm (MP_INT *, const MP_INT *, const MP_INT *, const MP_INT *);
136 void mpz_powm_ui (MP_INT *, const MP_INT *, unsigned long int, const MP_INT *);
137 void mpz_pow_ui (MP_INT *, const MP_INT *, unsigned long int);
138 void mpz_fac_ui (MP_INT *, unsigned long int);
139 void mpz_gcd (MP_INT *, const MP_INT *, const MP_INT *);
140 void mpz_gcdext (MP_INT *, MP_INT *, MP_INT *, const MP_INT *, const MP_INT *);
141 void mpz_neg (MP_INT *, const MP_INT *);
142 void mpz_com (MP_INT *, const MP_INT *);
143 void mpz_abs (MP_INT *, const MP_INT *);
144 int mpz_cmp (const MP_INT *, const MP_INT *);
145 int mpz_cmp_ui (const MP_INT *, unsigned long int);
146 int mpz_cmp_si (const MP_INT *, signed long int);
147 void mpz_mul_2exp (MP_INT *, const MP_INT *, unsigned long int);
148 void mpz_div_2exp (MP_INT *, const MP_INT *, unsigned long int);
149 void mpz_mod_2exp (MP_INT *, const MP_INT *, unsigned long int);
150 void mpz_and (MP_INT *, const MP_INT *, const MP_INT *);
151 void mpz_ior (MP_INT *, const MP_INT *, const MP_INT *);
152 void mpz_xor (MP_INT *, const MP_INT *, const MP_INT *);
153
154 #if defined (FILE) || defined (_STDIO_H) || defined (__STDIO_H__)
155 void mpz_inp_raw (MP_INT *, FILE *);
156 void mpz_inp_str (MP_INT *, FILE *, int);
157 void mpz_out_raw (FILE *, const MP_INT *);
158 void mpz_out_str (FILE *, int, const MP_INT *);
159 #endif
160
161 void mpz_array_init (MP_INT [], size_t, mp_size);
162 void mpz_random (MP_INT *, mp_size);
163 void mpz_random2 (MP_INT *, mp_size);
164 size_t mpz_size (const MP_INT *);
165 size_t mpz_sizeinbase (const MP_INT *, int);
166
167 /**************** Rational (i.e. Q) routines.  ****************/
168
169 void mpq_init (MP_RAT *);
170 void mpq_clear (MP_RAT *);
171 void mpq_set (MP_RAT *, const MP_RAT *);
172 void mpq_set_ui (MP_RAT *, unsigned long int, unsigned long int);
173 void mpq_set_si (MP_RAT *, signed long int, unsigned long int);
174 void mpq_add (MP_RAT *, const MP_RAT *, const MP_RAT *);
175 void mpq_sub (MP_RAT *, const MP_RAT *, const MP_RAT *);
176 void mpq_mul (MP_RAT *, const MP_RAT *, const MP_RAT *);
177 void mpq_div (MP_RAT *, const MP_RAT *, const MP_RAT *);
178 void mpq_neg (MP_RAT *, const MP_RAT *);
179 int mpq_cmp (const MP_RAT *, const MP_RAT *);
180 void mpq_inv (MP_RAT *, const MP_RAT *);
181 void mpq_set_num (MP_RAT *, const MP_INT *);
182 void mpq_set_den (MP_RAT *, const MP_INT *);
183 void mpq_get_num (MP_INT *, const MP_RAT *);
184 void mpq_get_den (MP_INT *, const MP_RAT *);
185
186 /************ Low level positive-integer (i.e. N) routines.  ************/
187
188 mp_limb mpn_add (mp_ptr, mp_srcptr, mp_size, mp_srcptr, mp_size);
189 mp_size mpn_sub (mp_ptr, mp_srcptr, mp_size, mp_srcptr, mp_size);
190 mp_size mpn_mul (mp_ptr, mp_srcptr, mp_size, mp_srcptr, mp_size);
191 mp_size mpn_div (mp_ptr, mp_ptr, mp_size, mp_srcptr, mp_size);
192 mp_limb mpn_divmod_1 (mp_ptr, mp_srcptr, mp_size, mp_limb);
193 mp_limb mpn_mod_1 (mp_srcptr, mp_size, mp_limb);
194 mp_limb mpn_lshift (mp_ptr, mp_srcptr, mp_size, unsigned int);
195 mp_size mpn_rshift (mp_ptr, mp_srcptr, mp_size, unsigned int);
196 mp_size mpn_rshiftci (mp_ptr, mp_srcptr, mp_size, unsigned int, mp_limb);
197 mp_size mpn_sqrt (mp_ptr, mp_ptr, mp_srcptr, mp_size);
198 int mpn_cmp (mp_srcptr, mp_srcptr, mp_size);
199
200 #else /* ! __STDC__ */
201 void mp_set_memory_functions ();
202
203 /**************** Integer (i.e. Z) routines.  ****************/
204
205 void mpz_init ();
206 void mpz_set ();
207 void mpz_set_ui ();
208 void mpz_set_si ();
209 int mpz_set_str ();
210 void mpz_init_set ();
211 void mpz_init_set_ui ();
212 void mpz_init_set_si ();
213 int mpz_init_set_str ();
214 unsigned long int mpz_get_ui ();
215 long int mpz_get_si ();
216 char * mpz_get_str ();
217 void mpz_clear ();
218 void * _mpz_realloc ();
219 void mpz_add ();
220 void mpz_add_ui ();
221 void mpz_sub ();
222 void mpz_sub_ui ();
223 void mpz_mul ();
224 void mpz_mul_ui ();
225 void mpz_div ();
226 void mpz_div_ui ();
227 void mpz_mod ();
228 void mpz_mod_ui ();
229 void mpz_divmod ();
230 void mpz_divmod_ui ();
231 void mpz_mdiv ();
232 void mpz_mdiv_ui ();
233 void mpz_mmod ();
234 unsigned long int mpz_mmod_ui ();
235 void mpz_mdivmod ();
236 unsigned long int mpz_mdivmod_ui ();
237 void mpz_sqrt ();
238 void mpz_sqrtrem ();
239 int mpz_perfect_square_p ();
240 int mpz_probab_prime_p ();
241 void mpz_powm ();
242 void mpz_powm_ui ();
243 void mpz_pow_ui ();
244 void mpz_fac_ui ();
245 void mpz_gcd ();
246 void mpz_gcdext ();
247 void mpz_neg ();
248 void mpz_com ();
249 void mpz_abs ();
250 int mpz_cmp ();
251 int mpz_cmp_ui ();
252 int mpz_cmp_si ();
253 void mpz_mul_2exp ();
254 void mpz_div_2exp ();
255 void mpz_mod_2exp ();
256 void mpz_and ();
257 void mpz_ior ();
258 void mpz_xor ();
259
260 void mpz_inp_raw ();
261 void mpz_inp_str ();
262 void mpz_out_raw ();
263 void mpz_out_str ();
264
265 void mpz_array_init ();
266 void mpz_random ();
267 void mpz_random2 ();
268 size_t mpz_size ();
269 size_t mpz_sizeinbase ();
270
271 /**************** Rational (i.e. Q) routines.  ****************/
272
273 void mpq_init ();
274 void mpq_clear ();
275 void mpq_set ();
276 void mpq_set_ui ();
277 void mpq_set_si ();
278 void mpq_add ();
279 void mpq_sub ();
280 void mpq_mul ();
281 void mpq_div ();
282 void mpq_neg ();
283 int mpq_cmp ();
284 void mpq_inv ();
285 void mpq_set_num ();
286 void mpq_set_den ();
287 void mpq_get_num ();
288 void mpq_get_den ();
289
290 /************ Low level positive-integer (i.e. N) routines.  ************/
291
292 mp_limb mpn_add ();
293 mp_size mpn_sub ();
294 mp_size mpn_mul ();
295 mp_size mpn_div ();
296 mp_limb mpn_lshift ();
297 mp_size mpn_rshift ();
298 mp_size mpn_rshiftci ();
299 int mpn_cmp ();
300 #endif /* __STDC__ */
301
302 #endif /* __GMP_H__ */