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

source code of glibc/stdlib/gmp.h