1 /* gmp.h -- Definitions for GNU multiple precision functions.
3 Copyright (C) 1991, 1993 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 General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
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.
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. */
35 long int alloc; /* Number of *limbs* allocated and pointed
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
41 unsigned long int *d; /* Pointer to the limbs. */
46 short int alloc; /* Number of *limbs* allocated and pointed
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
52 unsigned long int *d; /* Pointer to the limbs. */
57 #define MP_INT __MP_INT
59 typedef unsigned long int mp_limb;
60 typedef long int mp_limb_signed;
61 typedef mp_limb * mp_ptr;
63 typedef const mp_limb * mp_srcptr;
65 typedef mp_limb * mp_srcptr;
67 typedef long int mp_size;
69 /* Structure for rational numbers. Zero is represented as 0/any, i.e.
70 the denominator is ignored. Negative numbers have the sign in
77 long int num_alloc; /* Number of limbs allocated
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. */
92 void mp_set_memory_functions (void *(*) (size_t),
93 void *(*) (void *, size_t, size_t),
94 void (*) (void *, size_t));
96 /**************** Integer (i.e. Z) routines. ****************/
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 *,
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 *);
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 *);
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);
167 /**************** Rational (i.e. Q) routines. ****************/
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 *);
186 /************ Low level positive-integer (i.e. N) routines. ************/
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);
200 #else /* ! __STDC__ */
201 void mp_set_memory_functions ();
203 /**************** Integer (i.e. Z) routines. ****************/
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 ();
218 void * _mpz_realloc ();
230 void mpz_divmod_ui ();
234 unsigned long int mpz_mmod_ui ();
236 unsigned long int mpz_mdivmod_ui ();
239 int mpz_perfect_square_p ();
240 int mpz_probab_prime_p ();
253 void mpz_mul_2exp ();
254 void mpz_div_2exp ();
255 void mpz_mod_2exp ();
265 void mpz_array_init ();
269 size_t mpz_sizeinbase ();
271 /**************** Rational (i.e. Q) routines. ****************/
290 /************ Low level positive-integer (i.e. N) routines. ************/
296 mp_limb mpn_lshift ();
297 mp_size mpn_rshift ();
298 mp_size mpn_rshiftci ();
300 #endif /* __STDC__ */
302 #endif /* __GMP_H__ */