Define FE_SNANS_ALWAYS_SIGNAL.
[glibc.git] / stdlib / gmp.h
bloba92fd36da3e5a6b0ea205315dbbebef4c39843fd
1 /* gmp.h -- Definitions for GNU multiple precision functions.
3 Copyright (C) 1991-2016 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library; see the file COPYING.LIB. If not, see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef __GMP_H__
23 #include <features.h>
25 #ifndef __GNU_MP__
26 #define __GNU_MP__ 2
27 #define __need_size_t
28 #include <stddef.h>
29 #undef __need_size_t
31 #if defined (__STDC__) || defined (__cplusplus)
32 #define __gmp_const const
33 #else
34 #define __gmp_const
35 #endif
37 #if defined (__GNUC__)
38 #define __gmp_inline __inline__
39 #else
40 #define __gmp_inline
41 #endif
43 #ifndef _EXTERN_INLINE
44 #ifdef __GNUC__
45 #define _EXTERN_INLINE __extern_inline
46 #else
47 #define _EXTERN_INLINE static
48 #endif
49 #endif
51 #ifdef _SHORT_LIMB
52 typedef unsigned int mp_limb_t;
53 typedef int mp_limb_signed_t;
54 #else
55 #ifdef _LONG_LONG_LIMB
56 typedef unsigned long long int mp_limb_t;
57 typedef long long int mp_limb_signed_t;
58 #else
59 typedef unsigned long int mp_limb_t;
60 typedef long int mp_limb_signed_t;
61 #endif
62 #endif
64 typedef mp_limb_t * mp_ptr;
65 typedef __gmp_const mp_limb_t * mp_srcptr;
66 typedef long int mp_size_t;
67 typedef long int mp_exp_t;
69 #ifndef __MP_SMALL__
70 typedef struct
72 int _mp_alloc; /* Number of *limbs* allocated and pointed
73 to by the D field. */
74 int _mp_size; /* abs(SIZE) is the number of limbs
75 the last field points to. If SIZE
76 is negative this is a negative
77 number. */
78 mp_limb_t *_mp_d; /* Pointer to the limbs. */
79 } __mpz_struct;
80 #else
81 typedef struct
83 short int _mp_alloc; /* Number of *limbs* allocated and pointed
84 to by the D field. */
85 short int _mp_size; /* abs(SIZE) is the number of limbs
86 the last field points to. If SIZE
87 is negative this is a negative
88 number. */
89 mp_limb_t *_mp_d; /* Pointer to the limbs. */
90 } __mpz_struct;
91 #endif
92 #endif /* __GNU_MP__ */
94 /* User-visible types. */
95 typedef __mpz_struct MP_INT;
96 typedef __mpz_struct mpz_t[1];
98 /* Structure for rational numbers. Zero is represented as 0/any, i.e.
99 the denominator is ignored. Negative numbers have the sign in
100 the numerator. */
101 typedef struct
103 __mpz_struct _mp_num;
104 __mpz_struct _mp_den;
105 #if 0
106 int _mp_num_alloc; /* Number of limbs allocated
107 for the numerator. */
108 int _mp_num_size; /* The absolute value of this field is the
109 length of the numerator; the sign is the
110 sign of the entire rational number. */
111 mp_ptr _mp_num; /* Pointer to the numerator limbs. */
112 int _mp_den_alloc; /* Number of limbs allocated
113 for the denominator. */
114 int _mp_den_size; /* Length of the denominator. (This field
115 should always be positive.) */
116 mp_ptr _mp_den; /* Pointer to the denominator limbs. */
117 #endif
118 } __mpq_struct;
120 typedef __mpq_struct MP_RAT;
121 typedef __mpq_struct mpq_t[1];
123 typedef struct
125 int _mp_prec; /* Max precision, in number of `mp_limb_t's.
126 Set by mpf_init and modified by
127 mpf_set_prec. The area pointed to
128 by the `d' field contains `prec' + 1
129 limbs. */
130 int _mp_size; /* abs(SIZE) is the number of limbs
131 the last field points to. If SIZE
132 is negative this is a negative
133 number. */
134 mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */
135 mp_limb_t *_mp_d; /* Pointer to the limbs. */
136 } __mpf_struct;
138 /* typedef __mpf_struct MP_FLOAT; */
139 typedef __mpf_struct mpf_t[1];
141 /* Types for function declarations in gmp files. */
142 /* ??? Should not pollute user name space with these ??? */
143 typedef __gmp_const __mpz_struct *mpz_srcptr;
144 typedef __mpz_struct *mpz_ptr;
145 typedef __gmp_const __mpf_struct *mpf_srcptr;
146 typedef __mpf_struct *mpf_ptr;
147 typedef __gmp_const __mpq_struct *mpq_srcptr;
148 typedef __mpq_struct *mpq_ptr;
150 #ifndef _PROTO
151 #if defined (__STDC__) || defined (__cplusplus)
152 #define _PROTO(x) x
153 #else
154 #define _PROTO(x) ()
155 #endif
156 #endif
158 #ifndef __MPN
159 #if defined (__STDC__) || defined (__cplusplus)
160 #define __MPN(x) __mpn_##x
161 #else
162 #define __MPN(x) __mpn_/**/x
163 #endif
164 #endif
166 #if defined (FILE) || defined (_STDIO_H_) || defined (__STDIO_H__) || defined (H_STDIO)
167 #define _GMP_H_HAVE_FILE 1
168 #endif
170 void mp_set_memory_functions _PROTO ((void *(*) (size_t),
171 void *(*) (void *, size_t, size_t),
172 void (*) (void *, size_t)));
173 extern const int mp_bits_per_limb;
175 /**************** Integer (i.e. Z) routines. ****************/
177 #if defined (__cplusplus)
178 extern "C" {
179 #endif
180 void *_mpz_realloc _PROTO ((mpz_ptr, mp_size_t));
182 void mpz_abs _PROTO ((mpz_ptr, mpz_srcptr));
183 void mpz_add _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
184 void mpz_add_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
185 void mpz_and _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
186 void mpz_array_init _PROTO ((mpz_ptr, mp_size_t, mp_size_t));
187 void mpz_cdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
188 unsigned long int mpz_cdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
189 void mpz_cdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
190 unsigned long int mpz_cdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
191 void mpz_cdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
192 unsigned long int mpz_cdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
193 unsigned long int mpz_cdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
194 void mpz_clear _PROTO ((mpz_ptr));
195 void mpz_clrbit _PROTO ((mpz_ptr, unsigned long int));
196 int mpz_cmp _PROTO ((mpz_srcptr, mpz_srcptr));
197 int mpz_cmp_si _PROTO ((mpz_srcptr, signed long int));
198 int mpz_cmp_ui _PROTO ((mpz_srcptr, unsigned long int));
199 void mpz_com _PROTO ((mpz_ptr, mpz_srcptr));
200 void mpz_divexact _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
201 void mpz_fac_ui _PROTO ((mpz_ptr, unsigned long int));
202 void mpz_fdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
203 void mpz_fdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
204 unsigned long int mpz_fdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
205 void mpz_fdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
206 unsigned long int mpz_fdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
207 void mpz_fdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
208 void mpz_fdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
209 unsigned long int mpz_fdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
210 unsigned long int mpz_fdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
211 void mpz_gcd _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
212 unsigned long int mpz_gcd_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
213 void mpz_gcdext _PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
214 /* signed */ long int mpz_get_si _PROTO ((mpz_srcptr));
215 char *mpz_get_str _PROTO ((char *, int, mpz_srcptr));
216 unsigned long int mpz_get_ui _PROTO ((mpz_srcptr));
217 mp_limb_t mpz_getlimbn _PROTO ((mpz_srcptr, mp_size_t));
218 unsigned long int mpz_hamdist _PROTO ((mpz_srcptr, mpz_srcptr));
219 void mpz_init _PROTO ((mpz_ptr));
220 #ifdef _GMP_H_HAVE_FILE
221 size_t mpz_inp_binary _PROTO ((mpz_ptr, FILE *));
222 size_t mpz_inp_raw _PROTO ((mpz_ptr, FILE *));
223 size_t mpz_inp_str _PROTO ((mpz_ptr, FILE *, int));
224 #endif
225 void mpz_init_set _PROTO ((mpz_ptr, mpz_srcptr));
226 void mpz_init_set_d _PROTO ((mpz_ptr, double));
227 void mpz_init_set_si _PROTO ((mpz_ptr, signed long int));
228 int mpz_init_set_str _PROTO ((mpz_ptr, const char *, int));
229 void mpz_init_set_ui _PROTO ((mpz_ptr, unsigned long int));
230 int mpz_invert _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
231 void mpz_ior _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
232 int mpz_jacobi _PROTO ((mpz_srcptr, mpz_srcptr));
233 int mpz_legendre _PROTO ((mpz_srcptr, mpz_srcptr));
234 void mpz_mod _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
235 void mpz_mul _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
236 void mpz_mul_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
237 void mpz_mul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
238 void mpz_neg _PROTO ((mpz_ptr, mpz_srcptr));
239 #ifdef _GMP_H_HAVE_FILE
240 size_t mpz_out_binary _PROTO ((FILE *, mpz_srcptr));
241 size_t mpz_out_raw _PROTO ((FILE *, mpz_srcptr));
242 size_t mpz_out_str _PROTO ((FILE *, int, mpz_srcptr));
243 #endif
244 int mpz_perfect_square_p _PROTO ((mpz_srcptr));
245 unsigned long int mpz_popcount _PROTO ((mpz_srcptr));
246 void mpz_pow_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
247 void mpz_powm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr));
248 void mpz_powm_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr));
249 int mpz_probab_prime_p _PROTO ((mpz_srcptr, int));
250 void mpz_random _PROTO ((mpz_ptr, mp_size_t));
251 void mpz_random2 _PROTO ((mpz_ptr, mp_size_t));
252 unsigned long int mpz_scan0 _PROTO ((mpz_srcptr, unsigned long int));
253 unsigned long int mpz_scan1 _PROTO ((mpz_srcptr, unsigned long int));
254 void mpz_set _PROTO ((mpz_ptr, mpz_srcptr));
255 void mpz_set_d _PROTO ((mpz_ptr, double));
256 void mpz_set_si _PROTO ((mpz_ptr, signed long int));
257 int mpz_set_str _PROTO ((mpz_ptr, const char *, int));
258 void mpz_set_ui _PROTO ((mpz_ptr, unsigned long int));
259 void mpz_setbit _PROTO ((mpz_ptr, unsigned long int));
260 size_t mpz_size _PROTO ((mpz_srcptr));
261 size_t mpz_sizeinbase _PROTO ((mpz_srcptr, int));
262 void mpz_sqrt _PROTO ((mpz_ptr, mpz_srcptr));
263 void mpz_sqrtrem _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr));
264 void mpz_sub _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
265 void mpz_sub_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
266 void mpz_tdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
267 void mpz_tdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
268 void mpz_tdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
269 void mpz_tdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
270 void mpz_tdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
271 void mpz_tdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
272 void mpz_tdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
273 void mpz_tdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
274 void mpz_ui_pow_ui _PROTO ((mpz_ptr, unsigned long int, unsigned long int));
276 /**************** Rational (i.e. Q) routines. ****************/
278 void mpq_init _PROTO ((mpq_ptr));
279 void mpq_clear _PROTO ((mpq_ptr));
280 void mpq_set _PROTO ((mpq_ptr, mpq_srcptr));
281 void mpq_set_ui _PROTO ((mpq_ptr, unsigned long int, unsigned long int));
282 void mpq_set_si _PROTO ((mpq_ptr, signed long int, unsigned long int));
283 void mpq_add _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
284 void mpq_sub _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
285 void mpq_mul _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
286 void mpq_div _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
287 void mpq_neg _PROTO ((mpq_ptr, mpq_srcptr));
288 int mpq_cmp _PROTO ((mpq_srcptr, mpq_srcptr));
289 int mpq_cmp_ui _PROTO ((mpq_srcptr, unsigned long int, unsigned long int));
290 void mpq_inv _PROTO ((mpq_ptr, mpq_srcptr));
291 void mpq_set_num _PROTO ((mpq_ptr, mpz_srcptr));
292 void mpq_set_den _PROTO ((mpq_ptr, mpz_srcptr));
293 void mpq_get_num _PROTO ((mpz_ptr, mpq_srcptr));
294 void mpq_get_den _PROTO ((mpz_ptr, mpq_srcptr));
295 double mpq_get_d _PROTO ((mpq_srcptr));
296 void mpq_canonicalize _PROTO ((mpq_ptr));
298 /**************** Float (i.e. F) routines. ****************/
300 void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
301 void mpf_add _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
302 void mpf_add_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
303 void mpf_clear _PROTO ((mpf_ptr));
304 int mpf_cmp _PROTO ((mpf_srcptr, mpf_srcptr));
305 int mpf_cmp_si _PROTO ((mpf_srcptr, signed long int));
306 int mpf_cmp_ui _PROTO ((mpf_srcptr, unsigned long int));
307 void mpf_div _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
308 void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
309 void mpf_div_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
310 void mpf_dump _PROTO ((mpf_srcptr));
311 int mpf_eq _PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int));
312 unsigned long int mpf_get_prec _PROTO ((mpf_srcptr));
313 char *mpf_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr));
314 void mpf_init _PROTO ((mpf_ptr));
315 void mpf_init2 _PROTO ((mpf_ptr, unsigned long int));
316 #ifdef _GMP_H_HAVE_FILE
317 size_t mpf_inp_str _PROTO ((mpf_ptr, FILE *, int));
318 #endif
319 void mpf_init_set _PROTO ((mpf_ptr, mpf_srcptr));
320 void mpf_init_set_d _PROTO ((mpf_ptr, double));
321 void mpf_init_set_si _PROTO ((mpf_ptr, signed long int));
322 int mpf_init_set_str _PROTO ((mpf_ptr, char *, int));
323 void mpf_init_set_ui _PROTO ((mpf_ptr, unsigned long int));
324 void mpf_mul _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
325 void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
326 void mpf_mul_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
327 void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
328 #ifdef _GMP_H_HAVE_FILE
329 size_t mpf_out_str _PROTO ((FILE *, int, size_t, mpf_srcptr));
330 #endif
331 void mpf_random2 _PROTO ((mpf_ptr, mp_size_t, mp_exp_t));
332 void mpf_reldiff _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
333 void mpf_set _PROTO ((mpf_ptr, mpf_srcptr));
334 void mpf_set_d _PROTO ((mpf_ptr, double));
335 void mpf_set_default_prec _PROTO ((unsigned long int));
336 void mpf_set_prec _PROTO ((mpf_ptr, unsigned long int));
337 void mpf_set_prec_raw _PROTO ((mpf_ptr, unsigned long int));
338 void mpf_set_si _PROTO ((mpf_ptr, signed long int));
339 int mpf_set_str _PROTO ((mpf_ptr, const char *, int));
340 void mpf_set_ui _PROTO ((mpf_ptr, unsigned long int));
341 size_t mpf_size _PROTO ((mpf_srcptr));
342 void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
343 void mpf_sqrt_ui _PROTO ((mpf_ptr, unsigned long int));
344 void mpf_sub _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
345 void mpf_sub_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
346 void mpf_ui_div _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
347 void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
348 #if defined (__cplusplus)
350 #endif
351 /************ Low level positive-integer (i.e. N) routines. ************/
353 /* This is ugly, but we need to make usr calls reach the prefixed function. */
354 #define mpn_add __MPN(add)
355 #define mpn_add_1 __MPN(add_1)
356 #define mpn_add_n __MPN(add_n)
357 #define mpn_addmul_1 __MPN(addmul_1)
358 #define mpn_bdivmod __MPN(bdivmod)
359 #define mpn_cmp __MPN(cmp)
360 #define mpn_divmod_1 __MPN(divmod_1)
361 #define mpn_divrem __MPN(divrem)
362 #define mpn_divrem_1 __MPN(divrem_1)
363 #define mpn_dump __MPN(dump)
364 #define mpn_gcd __MPN(gcd)
365 #define mpn_gcd_1 __MPN(gcd_1)
366 #define mpn_gcdext __MPN(gcdext)
367 #define mpn_get_str __MPN(get_str)
368 #define mpn_hamdist __MPN(hamdist)
369 #define mpn_lshift __MPN(lshift)
370 #define mpn_mod_1 __MPN(mod_1)
371 #define mpn_mul __MPN(mul)
372 #define mpn_mul_1 __MPN(mul_1)
373 #define mpn_mul_n __MPN(mul_n)
374 #define mpn_perfect_square_p __MPN(perfect_square_p)
375 #define mpn_popcount __MPN(popcount)
376 #define mpn_preinv_mod_1 __MPN(preinv_mod_1)
377 #define mpn_random2 __MPN(random2)
378 #define mpn_rshift __MPN(rshift)
379 #define mpn_scan0 __MPN(scan0)
380 #define mpn_scan1 __MPN(scan1)
381 #define mpn_set_str __MPN(set_str)
382 #define mpn_sqrtrem __MPN(sqrtrem)
383 #define mpn_sub __MPN(sub)
384 #define mpn_sub_1 __MPN(sub_1)
385 #define mpn_sub_n __MPN(sub_n)
386 #define mpn_submul_1 __MPN(submul_1)
387 #define mpn_udiv_w_sdiv __MPN(udiv_w_sdiv)
389 #if defined (__cplusplus)
390 extern "C" {
391 #endif
392 mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
393 mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
394 mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
395 mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
396 mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
397 int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
398 mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
399 mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
400 mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
401 void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
402 mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
403 mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
404 mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
405 size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
406 unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
407 mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
408 mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
409 mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
410 mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
411 void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
412 int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
413 unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
414 mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
415 void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
416 mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
417 unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
418 unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
419 mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
420 mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
421 mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
422 mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
423 mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
424 mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
425 #if defined (__cplusplus)
427 #endif
429 #if defined (__GNUC__) || defined (_FORCE_INLINES)
430 _EXTERN_INLINE mp_limb_t
431 #if defined (__STDC__) || defined (__cplusplus)
432 mpn_add_1 (register mp_ptr res_ptr,
433 register mp_srcptr s1_ptr,
434 register mp_size_t s1_size,
435 register mp_limb_t s2_limb)
436 #else
437 mpn_add_1 (res_ptr, s1_ptr, s1_size, s2_limb)
438 register mp_ptr res_ptr;
439 register mp_srcptr s1_ptr;
440 register mp_size_t s1_size;
441 register mp_limb_t s2_limb;
442 #endif
444 register mp_limb_t x;
446 x = *s1_ptr++;
447 s2_limb = x + s2_limb;
448 *res_ptr++ = s2_limb;
449 if (s2_limb < x)
451 while (--s1_size != 0)
453 x = *s1_ptr++ + 1;
454 *res_ptr++ = x;
455 if (x != 0)
456 goto fin;
459 return 1;
462 fin:
463 if (res_ptr != s1_ptr)
465 mp_size_t i;
466 for (i = 0; i < s1_size - 1; i++)
467 res_ptr[i] = s1_ptr[i];
469 return 0;
472 _EXTERN_INLINE mp_limb_t
473 #if defined (__STDC__) || defined (__cplusplus)
474 mpn_add (register mp_ptr res_ptr,
475 register mp_srcptr s1_ptr,
476 register mp_size_t s1_size,
477 register mp_srcptr s2_ptr,
478 register mp_size_t s2_size)
479 #else
480 mpn_add (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
481 register mp_ptr res_ptr;
482 register mp_srcptr s1_ptr;
483 register mp_size_t s1_size;
484 register mp_srcptr s2_ptr;
485 register mp_size_t s2_size;
486 #endif
488 mp_limb_t cy_limb = 0;
490 if (s2_size != 0)
491 cy_limb = mpn_add_n (res_ptr, s1_ptr, s2_ptr, s2_size);
493 if (s1_size - s2_size != 0)
494 cy_limb = mpn_add_1 (res_ptr + s2_size,
495 s1_ptr + s2_size,
496 s1_size - s2_size,
497 cy_limb);
498 return cy_limb;
501 _EXTERN_INLINE mp_limb_t
502 #if defined (__STDC__) || defined (__cplusplus)
503 mpn_sub_1 (register mp_ptr res_ptr,
504 register mp_srcptr s1_ptr,
505 register mp_size_t s1_size,
506 register mp_limb_t s2_limb)
507 #else
508 mpn_sub_1 (res_ptr, s1_ptr, s1_size, s2_limb)
509 register mp_ptr res_ptr;
510 register mp_srcptr s1_ptr;
511 register mp_size_t s1_size;
512 register mp_limb_t s2_limb;
513 #endif
515 register mp_limb_t x;
517 x = *s1_ptr++;
518 s2_limb = x - s2_limb;
519 *res_ptr++ = s2_limb;
520 if (s2_limb > x)
522 while (--s1_size != 0)
524 x = *s1_ptr++;
525 *res_ptr++ = x - 1;
526 if (x != 0)
527 goto fin;
530 return 1;
533 fin:
534 if (res_ptr != s1_ptr)
536 mp_size_t i;
537 for (i = 0; i < s1_size - 1; i++)
538 res_ptr[i] = s1_ptr[i];
540 return 0;
543 _EXTERN_INLINE mp_limb_t
544 #if defined (__STDC__) || defined (__cplusplus)
545 mpn_sub (register mp_ptr res_ptr,
546 register mp_srcptr s1_ptr,
547 register mp_size_t s1_size,
548 register mp_srcptr s2_ptr,
549 register mp_size_t s2_size)
550 #else
551 mpn_sub (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
552 register mp_ptr res_ptr;
553 register mp_srcptr s1_ptr;
554 register mp_size_t s1_size;
555 register mp_srcptr s2_ptr;
556 register mp_size_t s2_size;
557 #endif
559 mp_limb_t cy_limb = 0;
561 if (s2_size != 0)
562 cy_limb = mpn_sub_n (res_ptr, s1_ptr, s2_ptr, s2_size);
564 if (s1_size - s2_size != 0)
565 cy_limb = mpn_sub_1 (res_ptr + s2_size,
566 s1_ptr + s2_size,
567 s1_size - s2_size,
568 cy_limb);
569 return cy_limb;
571 #endif /* __GNUC__ */
573 /* Allow faster testing for negative, zero, and positive. */
574 #define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
575 #define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
576 #define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)
578 /* Allow direct user access to numerator and denominator of a mpq_t object. */
579 #define mpq_numref(Q) (&((Q)->_mp_num))
580 #define mpq_denref(Q) (&((Q)->_mp_den))
582 /* When using GCC, optimize certain common comparisons. */
583 #if defined (__GNUC__)
584 #define mpz_cmp_ui(Z,UI) \
585 (__builtin_constant_p (UI) && (UI) == 0 \
586 ? mpz_sgn (Z) : mpz_cmp_ui (Z,UI))
587 #define mpz_cmp_si(Z,UI) \
588 (__builtin_constant_p (UI) && (UI) == 0 ? mpz_sgn (Z) \
589 : __builtin_constant_p (UI) && (UI) > 0 ? mpz_cmp_ui (Z,UI) \
590 : mpz_cmp_si (Z,UI))
591 #define mpq_cmp_ui(Q,NUI,DUI) \
592 (__builtin_constant_p (NUI) && (NUI) == 0 \
593 ? mpq_sgn (Q) : mpq_cmp_ui (Q,NUI,DUI))
594 #endif
596 #define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize)
597 #if 0
598 #define mpn_divmod_1(qp,np,nsize,dlimb) mpn_divrem_1 (qp,0,np,nsize,dlimb)
599 #endif
601 /* Compatibility with GMP 1. */
602 #define mpz_mdiv mpz_fdiv_q
603 #define mpz_mdivmod mpz_fdiv_qr
604 #define mpz_mmod mpz_fdiv_r
605 #define mpz_mdiv_ui mpz_fdiv_q_ui
606 #define mpz_mdivmod_ui(q,r,n,d) \
607 ((r == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
608 #define mpz_mmod_ui(r,n,d) \
609 ((r == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))
611 /* Useful synonyms, but not quite compatible with GMP 1. */
612 #define mpz_div mpz_fdiv_q
613 #define mpz_divmod mpz_fdiv_qr
614 #define mpz_div_ui mpz_fdiv_q_ui
615 #define mpz_divmod_ui mpz_fdiv_qr_ui
616 #define mpz_mod_ui mpz_fdiv_r_ui
617 #define mpz_div_2exp mpz_fdiv_q_2exp
618 #define mpz_mod_2exp mpz_fdiv_r_2exp
620 #define __GNU_MP_VERSION 2
621 #define __GNU_MP_VERSION_MINOR 0
622 #define __GMP_H__
623 #endif /* __GMP_H__ */