1 // Copyright © 2017–2021 Trevor Spiteri
2
3 // This program is free software: you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public License
5 // as published by the Free Software Foundation, either version 3 of
6 // the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License and a copy of the GNU General Public License along with
15 // this program. If not, see <https://www.gnu.org/licenses/>.
16
17 /*!
18 Function and type bindings for the [GMP] library.
19
20 # Examples
21
22 ```rust
23 use core::mem::MaybeUninit;
24 use gmp_mpfr_sys::gmp;
25 unsafe {
26 let mut z = MaybeUninit::uninit();
27 gmp::mpz_init(z.as_mut_ptr());
28 let mut z = z.assume_init();
29 gmp::mpz_set_ui(&mut z, 15);
30 let u = gmp::mpz_get_ui(&z);
31 assert_eq!(u, 15);
32 gmp::mpz_clear(&mut z);
33 }
34 ```
35
36 [GMP]: https://gmplib.org/
37 */
38 #![allow(non_camel_case_types, non_snake_case)]
39 #![allow(clippy::cmp_owned)]
40
41 use core::{
42 cmp::Ordering,
43 fmt::{Debug, Formatter, Result as FmtResult},
44 mem::MaybeUninit,
45 ptr::NonNull,
46 };
47 use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void, FILE};
48
49 include!(concat!(env!("OUT_DIR"), "/gmp_h.rs"));
50
51 extern "C" {
52 /// See: [`mp_bits_per_limb`](../C/GMP/constant.GMP_Basics.html#index-mp_005fbits_005fper_005flimb)
53 #[link_name = "__gmp_bits_per_limb"]
54 pub static bits_per_limb: c_int;
55 }
56 /// See: [`__GNU_MP_VERSION`](../C/GMP/constant.GMP_Basics.html#index-_005f_005fGNU_005fMP_005fVERSION)
57 pub const VERSION: c_int = GMP_VERSION;
58 /// See: [`__GNU_MP_VERSION_MINOR`](../C/GMP/constant.GMP_Basics.html#index-_005f_005fGNU_005fMP_005fVERSION_005fMINOR)
59 pub const VERSION_MINOR: c_int = GMP_VERSION_MINOR;
60 /// See: [`__GNU_MP_VERSION_PATCHLEVEL`](../C/GMP/constant.GMP_Basics.html#index-_005f_005fGNU_005fMP_005fVERSION_005fPATCHLEVEL)
61 pub const VERSION_PATCHLEVEL: c_int = GMP_VERSION_PATCHLEVEL;
62 extern "C" {
63 /// See: [`gmp_version`](../C/GMP/constant.GMP_Basics.html#index-gmp_005fversion)
64 #[link_name = "__gmp_version"]
65 pub static version: *const c_char;
66 }
67 /// See: [`__GMP_CC`](../C/GMP/constant.GMP_Basics.html#index-_005f_005fGMP_005fCC)
68 pub const CC: *const c_char = GMP_CC;
69 /// See: [`__GMP_CFLAGS`](../C/GMP/constant.GMP_Basics.html#index-_005f_005fGMP_005fCFLAGS)
70 pub const CFLAGS: *const c_char = GMP_CFLAGS;
71
72 /// See: [`GMP_NAIL_BITS`](../C/GMP/constant.Low_level_Functions.html#index-GMP_005fNAIL_005fBITS)
73 pub const NAIL_BITS: c_int = GMP_NAIL_BITS;
74 /// See: [`GMP_NUMB_BITS`](../C/GMP/constant.Low_level_Functions.html#index-GMP_005fNUMB_005fBITS)
75 pub const NUMB_BITS: c_int = LIMB_BITS - NAIL_BITS;
76 /// See: [`GMP_LIMB_BITS`](../C/GMP/constant.Low_level_Functions.html#index-GMP_005fLIMB_005fBITS)
77 pub const LIMB_BITS: c_int = GMP_LIMB_BITS;
78 /// See: [`GMP_NAIL_MASK`](../C/GMP/constant.Low_level_Functions.html#index-GMP_005fNAIL_005fMASK)
79 pub const NAIL_MASK: limb_t = !NUMB_MASK;
80 /// See: [`GMP_NUMB_MASK`](../C/GMP/constant.Low_level_Functions.html#index-GMP_005fNUMB_005fMASK)
81 pub const NUMB_MASK: limb_t = (!(0 as limb_t)) >> NAIL_BITS;
82 /// See: [`GMP_NUMB_MAX`](../C/GMP/constant.Low_level_Functions.html#index-GMP_005fNUMB_005fMAX)
83 pub const NUMB_MAX: limb_t = NUMB_MASK;
84
85 /// See: [`mp_exp_t`](../C/GMP/constant.GMP_Basics.html#index-mp_005fexp_005ft)
86 pub type exp_t = c_long;
87 /// See: [`mp_limb_t`](../C/GMP/constant.GMP_Basics.html#index-mp_005flimb_005ft)
88 pub type limb_t = GMP_LIMB_T;
89 /// See: [`mp_size_t`](../C/GMP/constant.GMP_Basics.html#index-mp_005fsize_005ft)
90 pub type size_t = c_long;
91 /// See: [`mp_bitcnt_t`](../C/GMP/constant.GMP_Basics.html#index-mp_005fbitcnt_005ft)
92 pub type bitcnt_t = c_ulong;
93
94 /// See: [`mpz_t`](../C/GMP/constant.GMP_Basics.html#index-mpz_005ft)
95 /// and [Integer Internals](../C/GMP/constant.Internals.html#Integer-Internals)
96 ///
97 /// # Future compatibility
98 ///
99 /// The fields listed here are considered internal details. These
100 /// internals may change in new minor releases of this crate, though
101 /// they will be kept unchanged for patch releases. Any code that
102 /// makes use of these internals should list the dependency as
103 /// `version = "~1.4"` inside [*Cargo.toml*], *not* `version = "1.4"`.
104 ///
105 /// [*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
106 #[repr(C)]
107 #[derive(Clone, Copy, Debug)]
108 pub struct mpz_t {
109 /// See: [Integer Internals](../C/GMP/constant.Internals.html#Integer-Internals)
110 pub alloc: c_int,
111 /// See: [Integer Internals](../C/GMP/constant.Internals.html#Integer-Internals)
112 pub size: c_int,
113 /// See: [Integer Internals](../C/GMP/constant.Internals.html#Integer-Internals)
114 pub d: NonNull<limb_t>,
115 }
116
117 /// See: [`mpq_t`](../C/GMP/constant.GMP_Basics.html#index-mpq_005ft)
118 /// and [Rational Internals](../C/GMP/constant.Internals.html#Rational-Internals)
119 ///
120 /// # Future compatibility
121 ///
122 /// The fields listed here are considered internal details. These
123 /// internals may change in new minor releases of this crate, though
124 /// they will be kept unchanged for patch releases. Any code that
125 /// makes use of these internals should list the dependency as
126 /// `version = "~1.4"` inside [*Cargo.toml*], *not* `version = "1.4"`.
127 ///
128 /// [*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
129 ///
130 #[repr(C)]
131 #[derive(Clone, Copy, Debug)]
132 pub struct mpq_t {
133 /// Internal implementation detail: numerator.
134 pub num: mpz_t,
135 /// Internal implementation detail: denominator.
136 pub den: mpz_t,
137 }
138
139 /// See: [`mpf_t`](../C/GMP/constant.GMP_Basics.html#index-mpf_005ft)
140 /// and [Float Internals](../C/GMP/constant.Internals.html#Float-Internals)
141 ///
142 /// # Future compatibility
143 ///
144 /// The fields listed here are considered internal details. These
145 /// internals may change in new minor releases of this crate, though
146 /// they will be kept unchanged for patch releases. Any code that
147 /// makes use of these internals should list the dependency as
148 /// `version = "~1.4"` inside [*Cargo.toml*], *not* `version = "1.4"`.
149 ///
150 /// [*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
151 #[repr(C)]
152 #[derive(Clone, Copy, Debug)]
153 pub struct mpf_t {
154 /// See: [Float Internals](../C/GMP/constant.Internals.html#Float-Internals)
155 pub prec: c_int,
156 /// See: [Float Internals](../C/GMP/constant.Internals.html#Float-Internals)
157 pub size: c_int,
158 /// See: [Float Internals](../C/GMP/constant.Internals.html#Float-Internals)
159 pub exp: exp_t,
160 /// See: [Float Internals](../C/GMP/constant.Internals.html#Float-Internals)
161 pub d: NonNull<limb_t>,
162 }
163
164 /// See: [`gmp_randstate_t`](../C/GMP/constant.GMP_Basics.html#index-gmp_005frandstate_005ft)
165 ///
166 /// # Future compatibility
167 ///
168 /// The fields listed here are considered internal details. These
169 /// internals may change in new minor releases of this crate, though
170 /// they will be kept unchanged for patch releases. Any code that
171 /// makes use of these internals should list the dependency as
172 /// `version = "~1.4"` inside [*Cargo.toml*], *not* `version = "1.4"`.
173 ///
174 /// [*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
175 #[repr(C)]
176 #[derive(Clone, Copy)]
177 pub struct randstate_t {
178 /// Internal implementation detail: state of the generator.
179 pub seed: randseed_t,
180 /// Internal implementation detail: unused.
181 pub alg: MaybeUninit<c_int>,
182 /// Internal implementation detail: pointer to function pointers
183 /// structure.
184 pub algdata: *const randfnptr_t,
185 }
186
187 impl Debug for randstate_t {
fmt(&self, f: &mut Formatter<'_>) -> FmtResult188 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
189 f.debug_struct("randstate_t")
190 .field("seed", &self.seed)
191 .field("alg", &"unused")
192 .field("algdata", &self.algdata)
193 .finish()
194 }
195 }
196
197 /// The type for the [`seed`] field in the [`randstate_t`] struct.
198 ///
199 /// # Future compatibility
200 ///
201 /// This type is considered internal details. These internals may
202 /// change in new minor releases of this crate, though they will be
203 /// kept unchanged for patch releases. Any code that makes use of
204 /// these internals should list the dependency as `version = "~1.4"`
205 /// inside [*Cargo.toml*], *not* `version = "1.4"`.
206 ///
207 /// [*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
208 /// [`seed`]: `randstate_t::seed`
209 #[repr(C)]
210 #[derive(Clone, Copy)]
211 pub struct randseed_t {
212 /// Internal implementation detail: unused.
213 pub alloc: MaybeUninit<c_int>,
214 /// Internal implementation detail: unused.
215 pub size: MaybeUninit<c_int>,
216 /// Internal implementation detail: state of the generator.
217 pub d: NonNull<c_void>,
218 }
219
220 impl Debug for randseed_t {
fmt(&self, f: &mut Formatter<'_>) -> FmtResult221 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
222 f.debug_struct("randseed_t")
223 .field("alloc", &"unused")
224 .field("size", &"unused")
225 .field("d", &self.d)
226 .finish()
227 }
228 }
229
230 /// The type for the [`algdata`] field in the [`randstate_t`] struct.
231 ///
232 /// # Future compatibility
233 ///
234 /// This type is considered internal details. These internals may
235 /// change in new minor releases of this crate, though they will be
236 /// kept unchanged for patch releases. Any code that makes use of
237 /// these internals should list the dependency as `version = "~1.4"`
238 /// inside [*Cargo.toml*], *not* `version = "1.4"`.
239 ///
240 /// [*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
241 /// [`algdata`]: `randstate_t::algdata`
242 #[repr(C)]
243 #[derive(Clone, Copy, Debug)]
244 pub struct randfnptr_t {
245 /// Internal implementation detail: pointer to function.
246 pub seed: unsafe extern "C" fn(rstate: *mut randstate_t, seed: *const mpz_t),
247 /// Internal implementation detail: pointer to function.
248 pub get: unsafe extern "C" fn(rstate: *mut randstate_t, dest: *mut limb_t, nbits: c_ulong),
249 /// Internal implementation detail: pointer to function.
250 pub clear: unsafe extern "C" fn(rstate: *mut randstate_t),
251 /// Internal implementation detail: pointer to function.
252 pub iset: unsafe extern "C" fn(dst: *mut randstate_t, src: *const randstate_t),
253 }
254
255 // Types for function declarations in this file.
256
257 type mpz_srcptr = *const mpz_t;
258 type mpz_ptr = *mut mpz_t;
259 type mpq_srcptr = *const mpq_t;
260 type mpq_ptr = *mut mpq_t;
261 type mpf_srcptr = *const mpf_t;
262 type mpf_ptr = *mut mpf_t;
263 type mp_ptr = *mut limb_t;
264 type mp_srcptr = *const limb_t;
265 type randstate_srcptr = *const randstate_t;
266 type randstate_ptr = *mut randstate_t;
267
268 // Integers
269
270 // Initialization Functions
271
272 extern "C" {
273 /// See: [`mpz_init`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit)
274 #[link_name = "__gmpz_init"]
mpz_init(x: mpz_ptr)275 pub fn mpz_init(x: mpz_ptr);
276 #[link_name = "__gmpz_inits"]
277 /// See: [`mpz_inits`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finits)
mpz_inits(x: mpz_ptr, ...)278 pub fn mpz_inits(x: mpz_ptr, ...);
279 #[link_name = "__gmpz_init2"]
280 /// See: [`mpz_init2`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit2)
mpz_init2(x: mpz_ptr, n: bitcnt_t)281 pub fn mpz_init2(x: mpz_ptr, n: bitcnt_t);
282 #[link_name = "__gmpz_clear"]
283 /// See: [`mpz_clear`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fclear)
mpz_clear(x: mpz_ptr)284 pub fn mpz_clear(x: mpz_ptr);
285 #[link_name = "__gmpz_clears"]
286 /// See: [`mpz_clears`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fclears)
mpz_clears(x: mpz_ptr, ...)287 pub fn mpz_clears(x: mpz_ptr, ...);
288 #[link_name = "__gmpz_realloc2"]
289 /// See: [`mpz_realloc2`](../C/GMP/constant.Integer_Functions.html#index-mpz_005frealloc2)
mpz_realloc2(x: mpz_ptr, n: bitcnt_t)290 pub fn mpz_realloc2(x: mpz_ptr, n: bitcnt_t);
291
292 // Assignment Functions
293
294 /// See: [`mpz_set`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset)
295 #[link_name = "__gmpz_set"]
mpz_set(rop: mpz_ptr, op: mpz_srcptr)296 pub fn mpz_set(rop: mpz_ptr, op: mpz_srcptr);
297 /// See: [`mpz_set_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset_005fui)
298 #[link_name = "__gmpz_set_ui"]
mpz_set_ui(rop: mpz_ptr, op: c_ulong)299 pub fn mpz_set_ui(rop: mpz_ptr, op: c_ulong);
300 /// See: [`mpz_set_si`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset_005fsi)
301 #[link_name = "__gmpz_set_si"]
mpz_set_si(rop: mpz_ptr, op: c_long)302 pub fn mpz_set_si(rop: mpz_ptr, op: c_long);
303 /// See: [`mpz_set_d`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset_005fd)
304 #[link_name = "__gmpz_set_d"]
mpz_set_d(rop: mpz_ptr, op: f64)305 pub fn mpz_set_d(rop: mpz_ptr, op: f64);
306 }
307 /// See: [`mpz_set_q`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset_005fq)
308 #[inline]
mpz_set_q(rop: mpz_ptr, op: mpq_srcptr)309 pub unsafe extern "C" fn mpz_set_q(rop: mpz_ptr, op: mpq_srcptr) {
310 unsafe { mpz_tdiv_q(rop, mpq_numref_const(op), mpq_denref_const(op)) }
311 }
312 extern "C" {
313 /// See: [`mpz_set_f`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset_005ff)
314 #[link_name = "__gmpz_set_f"]
mpz_set_f(rop: mpz_ptr, op: mpf_srcptr)315 pub fn mpz_set_f(rop: mpz_ptr, op: mpf_srcptr);
316 /// See: [`mpz_set_str`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fset_005fstr)
317 #[link_name = "__gmpz_set_str"]
mpz_set_str(rop: mpz_ptr, str: *const c_char, base: c_int) -> c_int318 pub fn mpz_set_str(rop: mpz_ptr, str: *const c_char, base: c_int) -> c_int;
319 /// See: [`mpz_swap`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fswap)
320 #[link_name = "__gmpz_swap"]
mpz_swap(rop1: mpz_ptr, rop2: mpz_ptr)321 pub fn mpz_swap(rop1: mpz_ptr, rop2: mpz_ptr);
322
323 // Combined Initialization and Assignment Functions
324
325 /// See: [`mpz_init_set`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit_005fset)
326 #[link_name = "__gmpz_init_set"]
mpz_init_set(rop: mpz_ptr, op: mpz_srcptr)327 pub fn mpz_init_set(rop: mpz_ptr, op: mpz_srcptr);
328 /// See: [`mpz_init_set_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit_005fset_005fui)
329 #[link_name = "__gmpz_init_set_ui"]
mpz_init_set_ui(rop: mpz_ptr, op: c_ulong)330 pub fn mpz_init_set_ui(rop: mpz_ptr, op: c_ulong);
331 /// See: [`mpz_init_set_si`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit_005fset_005fsi)
332 #[link_name = "__gmpz_init_set_si"]
mpz_init_set_si(rop: mpz_ptr, op: c_long)333 pub fn mpz_init_set_si(rop: mpz_ptr, op: c_long);
334 /// See: [`mpz_init_set_d`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit_005fset_005fd)
335 #[link_name = "__gmpz_init_set_d"]
mpz_init_set_d(rop: mpz_ptr, op: f64)336 pub fn mpz_init_set_d(rop: mpz_ptr, op: f64);
337 /// See: [`mpz_init_set_str`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finit_005fset_005fstr)
338 #[link_name = "__gmpz_init_set_str"]
mpz_init_set_str(rop: mpz_ptr, str: *const c_char, base: c_int) -> c_int339 pub fn mpz_init_set_str(rop: mpz_ptr, str: *const c_char, base: c_int) -> c_int;
340 }
341
342 // Conversion Functions
343
344 /// See: [`mpz_get_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fget_005fui)
345 #[inline]
346 #[cfg(any(not(nails), long_long_limb))]
mpz_get_ui(op: mpz_srcptr) -> c_ulong347 pub unsafe extern "C" fn mpz_get_ui(op: mpz_srcptr) -> c_ulong {
348 if unsafe { (*op).size } != 0 {
349 unsafe {
350 let p = (*op).d.as_ptr();
351 (*p) as c_ulong
352 }
353 } else {
354 0
355 }
356 }
357 /// See: [`mpz_get_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fget_005fui)
358 #[inline]
359 #[cfg(all(nails, not(long_long_limb)))]
mpz_get_ui(op: mpz_srcptr) -> c_ulong360 pub unsafe extern "C" fn mpz_get_ui(op: mpz_srcptr) -> c_ulong {
361 let p = unsafe { (*op).d };
362 let n = unsafe { (*op).size }.abs();
363 if n == 0 {
364 0
365 } else if n == 1 {
366 unsafe { *p }
367 } else {
368 unsafe { *p + ((*(p.offset(1))) << NUMB_BITS) }
369 }
370 }
371 extern "C" {
372 /// See: [`mpz_get_si`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fget_005fsi)
373 #[link_name = "__gmpz_get_si"]
mpz_get_si(op: mpz_srcptr) -> c_long374 pub fn mpz_get_si(op: mpz_srcptr) -> c_long;
375 /// See: [`mpz_get_d`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fget_005fd)
376 #[link_name = "__gmpz_get_d"]
mpz_get_d(op: mpz_srcptr) -> f64377 pub fn mpz_get_d(op: mpz_srcptr) -> f64;
378 /// See: [`mpz_get_d_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fget_005fd_005f2exp)
379 #[link_name = "__gmpz_get_d_2exp"]
mpz_get_d_2exp(exp: *mut c_long, op: mpz_srcptr) -> f64380 pub fn mpz_get_d_2exp(exp: *mut c_long, op: mpz_srcptr) -> f64;
381 /// See: [`mpz_get_str`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fget_005fstr)
382 #[link_name = "__gmpz_get_str"]
mpz_get_str(str: *mut c_char, base: c_int, op: mpz_srcptr) -> *mut c_char383 pub fn mpz_get_str(str: *mut c_char, base: c_int, op: mpz_srcptr) -> *mut c_char;
384
385 // Arithmetic Functions
386
387 /// See: [`mpz_add`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fadd)
388 #[link_name = "__gmpz_add"]
mpz_add(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)389 pub fn mpz_add(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
390 /// See: [`mpz_add_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fadd_005fui)
391 #[link_name = "__gmpz_add_ui"]
mpz_add_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong)392 pub fn mpz_add_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
393 /// See: [`mpz_sub`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsub)
394 #[link_name = "__gmpz_sub"]
mpz_sub(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)395 pub fn mpz_sub(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
396 /// See: [`mpz_sub_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsub_005fui)
397 #[link_name = "__gmpz_sub_ui"]
mpz_sub_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong)398 pub fn mpz_sub_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
399 /// See: [`mpz_ui_sub`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fui_005fsub)
400 #[link_name = "__gmpz_ui_sub"]
mpz_ui_sub(rop: mpz_ptr, op1: c_ulong, op2: mpz_srcptr)401 pub fn mpz_ui_sub(rop: mpz_ptr, op1: c_ulong, op2: mpz_srcptr);
402 /// See: [`mpz_mul`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmul)
403 #[link_name = "__gmpz_mul"]
mpz_mul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)404 pub fn mpz_mul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
405 /// See: [`mpz_mul_si`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmul_005fsi)
406 #[link_name = "__gmpz_mul_si"]
mpz_mul_si(rop: mpz_ptr, op1: mpz_srcptr, op2: c_long)407 pub fn mpz_mul_si(rop: mpz_ptr, op1: mpz_srcptr, op2: c_long);
408 /// See: [`mpz_mul_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmul_005fui)
409 #[link_name = "__gmpz_mul_ui"]
mpz_mul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong)410 pub fn mpz_mul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
411 /// See: [`mpz_addmul`](../C/GMP/constant.Integer_Functions.html#index-mpz_005faddmul)
412 #[link_name = "__gmpz_addmul"]
mpz_addmul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)413 pub fn mpz_addmul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
414 /// See: [`mpz_addmul_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005faddmul_005fui)
415 #[link_name = "__gmpz_addmul_ui"]
mpz_addmul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong)416 pub fn mpz_addmul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
417 /// See: [`mpz_submul`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsubmul)
418 #[link_name = "__gmpz_submul"]
mpz_submul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)419 pub fn mpz_submul(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
420 /// See: [`mpz_submul_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsubmul_005fui)
421 #[link_name = "__gmpz_submul_ui"]
mpz_submul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong)422 pub fn mpz_submul_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
423 /// See: [`mpz_mul_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmul_005f2exp)
424 #[link_name = "__gmpz_mul_2exp"]
mpz_mul_2exp(rop: mpz_ptr, op1: mpz_srcptr, op2: bitcnt_t)425 pub fn mpz_mul_2exp(rop: mpz_ptr, op1: mpz_srcptr, op2: bitcnt_t);
426 }
427 /// See: [`mpz_neg`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fneg)
428 #[inline]
mpz_neg(rop: mpz_ptr, op: mpz_srcptr)429 pub unsafe extern "C" fn mpz_neg(rop: mpz_ptr, op: mpz_srcptr) {
430 if rop as mpz_srcptr != op {
431 unsafe {
432 mpz_set(rop, op);
433 }
434 }
435 unsafe {
436 (*rop).size = -(*rop).size;
437 }
438 }
439 /// See: [`mpz_abs`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fabs)
440 #[inline]
mpz_abs(rop: mpz_ptr, op: mpz_srcptr)441 pub unsafe extern "C" fn mpz_abs(rop: mpz_ptr, op: mpz_srcptr) {
442 unsafe {
443 if rop as mpz_srcptr != op {
444 mpz_set(rop, op);
445 }
446 (*rop).size = (*rop).size.abs();
447 }
448 }
449
450 // Division Functions
451
452 extern "C" {
453 /// See: [`mpz_cdiv_q`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fq)
454 #[link_name = "__gmpz_cdiv_q"]
mpz_cdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)455 pub fn mpz_cdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
456 /// See: [`mpz_cdiv_r`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fr)
457 #[link_name = "__gmpz_cdiv_r"]
mpz_cdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)458 pub fn mpz_cdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
459 /// See: [`mpz_cdiv_qr`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fqr)
460 #[link_name = "__gmpz_cdiv_qr"]
mpz_cdiv_qr(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)461 pub fn mpz_cdiv_qr(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
462 /// See: [`mpz_cdiv_q_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fq_005fui)
463 #[link_name = "__gmpz_cdiv_q_ui"]
mpz_cdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong464 pub fn mpz_cdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
465 /// See: [`mpz_cdiv_r_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fr_005fui)
466 #[link_name = "__gmpz_cdiv_r_ui"]
mpz_cdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong467 pub fn mpz_cdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
468 /// See: [`mpz_cdiv_qr_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fqr_005fui)
469 #[link_name = "__gmpz_cdiv_qr_ui"]
mpz_cdiv_qr_ui(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong470 pub fn mpz_cdiv_qr_ui(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
471 /// See: [`mpz_cdiv_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fui)
472 #[link_name = "__gmpz_cdiv_ui"]
mpz_cdiv_ui(n: mpz_srcptr, d: c_ulong) -> c_ulong473 pub fn mpz_cdiv_ui(n: mpz_srcptr, d: c_ulong) -> c_ulong;
474 /// See: [`mpz_cdiv_q_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fq_005f2exp)
475 #[link_name = "__gmpz_cdiv_q_2exp"]
mpz_cdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: bitcnt_t)476 pub fn mpz_cdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: bitcnt_t);
477 /// See: [`mpz_cdiv_r_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcdiv_005fr_005f2exp)
478 #[link_name = "__gmpz_cdiv_r_2exp"]
mpz_cdiv_r_2exp(r: mpz_ptr, n: mpz_srcptr, b: bitcnt_t)479 pub fn mpz_cdiv_r_2exp(r: mpz_ptr, n: mpz_srcptr, b: bitcnt_t);
480 /// See: [`mpz_fdiv_q`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fq)
481 #[link_name = "__gmpz_fdiv_q"]
mpz_fdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)482 pub fn mpz_fdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
483 /// See: [`mpz_fdiv_r`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fr)
484 #[link_name = "__gmpz_fdiv_r"]
mpz_fdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)485 pub fn mpz_fdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
486 /// See: [`mpz_fdiv_qr`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fqr)
487 #[link_name = "__gmpz_fdiv_qr"]
mpz_fdiv_qr(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)488 pub fn mpz_fdiv_qr(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
489 /// See: [`mpz_fdiv_q_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fq_005fui)
490 #[link_name = "__gmpz_fdiv_q_ui"]
mpz_fdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong491 pub fn mpz_fdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
492 /// See: [`mpz_fdiv_r_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fr_005fui)
493 #[link_name = "__gmpz_fdiv_r_ui"]
mpz_fdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong494 pub fn mpz_fdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
495 /// See: [`mpz_fdiv_qr_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fqr_005fui)
496 #[link_name = "__gmpz_fdiv_qr_ui"]
mpz_fdiv_qr_ui(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong497 pub fn mpz_fdiv_qr_ui(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
498 /// See: [`mpz_fdiv_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fui)
499 #[link_name = "__gmpz_fdiv_ui"]
mpz_fdiv_ui(n: mpz_srcptr, d: c_ulong) -> c_ulong500 pub fn mpz_fdiv_ui(n: mpz_srcptr, d: c_ulong) -> c_ulong;
501 /// See: [`mpz_fdiv_q_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fq_005f2exp)
502 #[link_name = "__gmpz_fdiv_q_2exp"]
mpz_fdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: bitcnt_t)503 pub fn mpz_fdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: bitcnt_t);
504 /// See: [`mpz_fdiv_r_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffdiv_005fr_005f2exp)
505 #[link_name = "__gmpz_fdiv_r_2exp"]
mpz_fdiv_r_2exp(r: mpz_ptr, n: mpz_srcptr, b: bitcnt_t)506 pub fn mpz_fdiv_r_2exp(r: mpz_ptr, n: mpz_srcptr, b: bitcnt_t);
507 /// See: [`mpz_tdiv_q`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fq)
508 #[link_name = "__gmpz_tdiv_q"]
mpz_tdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)509 pub fn mpz_tdiv_q(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
510 /// See: [`mpz_tdiv_r`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fr)
511 #[link_name = "__gmpz_tdiv_r"]
mpz_tdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)512 pub fn mpz_tdiv_r(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
513 /// See: [`mpz_tdiv_qr`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fqr)
514 #[link_name = "__gmpz_tdiv_qr"]
mpz_tdiv_qr(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)515 pub fn mpz_tdiv_qr(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
516 /// See: [`mpz_tdiv_q_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fq_005fui)
517 #[link_name = "__gmpz_tdiv_q_ui"]
mpz_tdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong518 pub fn mpz_tdiv_q_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
519 /// See: [`mpz_tdiv_r_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fr_005fui)
520 #[link_name = "__gmpz_tdiv_r_ui"]
mpz_tdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong521 pub fn mpz_tdiv_r_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
522 /// See: [`mpz_tdiv_qr_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fqr_005fui)
523 #[link_name = "__gmpz_tdiv_qr_ui"]
mpz_tdiv_qr_ui(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong524 pub fn mpz_tdiv_qr_ui(q: mpz_ptr, r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong;
525 /// See: [`mpz_tdiv_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fui)
526 #[link_name = "__gmpz_tdiv_ui"]
mpz_tdiv_ui(n: mpz_srcptr, d: c_ulong) -> c_ulong527 pub fn mpz_tdiv_ui(n: mpz_srcptr, d: c_ulong) -> c_ulong;
528 /// See: [`mpz_tdiv_q_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fq_005f2exp)
529 #[link_name = "__gmpz_tdiv_q_2exp"]
mpz_tdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: bitcnt_t)530 pub fn mpz_tdiv_q_2exp(q: mpz_ptr, n: mpz_srcptr, b: bitcnt_t);
531 /// See: [`mpz_tdiv_r_2exp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftdiv_005fr_005f2exp)
532 #[link_name = "__gmpz_tdiv_r_2exp"]
mpz_tdiv_r_2exp(r: mpz_ptr, n: mpz_srcptr, b: bitcnt_t)533 pub fn mpz_tdiv_r_2exp(r: mpz_ptr, n: mpz_srcptr, b: bitcnt_t);
534 /// See: [`mpz_mod`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmod)
535 #[link_name = "__gmpz_mod"]
mpz_mod(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)536 pub fn mpz_mod(r: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
537 }
538 /// See: [`mpz_mod_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmod_005fui)
539 #[inline]
mpz_mod_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong540 pub unsafe extern "C" fn mpz_mod_ui(r: mpz_ptr, n: mpz_srcptr, d: c_ulong) -> c_ulong {
541 unsafe { mpz_fdiv_r_ui(r, n, d) }
542 }
543 extern "C" {
544 /// See: [`mpz_divexact`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fdivexact)
545 #[link_name = "__gmpz_divexact"]
mpz_divexact(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr)546 pub fn mpz_divexact(q: mpz_ptr, n: mpz_srcptr, d: mpz_srcptr);
547 /// See: [`mpz_divexact_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fdivexact_005fui)
548 #[link_name = "__gmpz_divexact_ui"]
mpz_divexact_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong)549 pub fn mpz_divexact_ui(q: mpz_ptr, n: mpz_srcptr, d: c_ulong);
550 /// See: [`mpz_divisible_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fdivisible_005fp)
551 #[link_name = "__gmpz_divisible_p"]
mpz_divisible_p(n: mpz_srcptr, d: mpz_srcptr) -> c_int552 pub fn mpz_divisible_p(n: mpz_srcptr, d: mpz_srcptr) -> c_int;
553 /// See: [`mpz_divisible_ui_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fdivisible_005fui_005fp)
554 #[link_name = "__gmpz_divisible_ui_p"]
mpz_divisible_ui_p(n: mpz_srcptr, d: c_ulong) -> c_int555 pub fn mpz_divisible_ui_p(n: mpz_srcptr, d: c_ulong) -> c_int;
556 /// See: [`mpz_divisible_2exp_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fdivisible_005f2exp_005fp)
557 #[link_name = "__gmpz_divisible_2exp_p"]
mpz_divisible_2exp_p(n: mpz_srcptr, b: bitcnt_t) -> c_int558 pub fn mpz_divisible_2exp_p(n: mpz_srcptr, b: bitcnt_t) -> c_int;
559 /// See: [`mpz_congruent_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcongruent_005fp)
560 #[link_name = "__gmpz_congruent_p"]
mpz_congruent_p(n: mpz_srcptr, c: mpz_srcptr, d: mpz_srcptr) -> c_int561 pub fn mpz_congruent_p(n: mpz_srcptr, c: mpz_srcptr, d: mpz_srcptr) -> c_int;
562 /// See: [`mpz_congruent_ui_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcongruent_005fui_005fp)
563 #[link_name = "__gmpz_congruent_ui_p"]
mpz_congruent_ui_p(n: mpz_srcptr, c: c_ulong, d: c_ulong) -> c_int564 pub fn mpz_congruent_ui_p(n: mpz_srcptr, c: c_ulong, d: c_ulong) -> c_int;
565 /// See: [`mpz_congruent_2exp_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcongruent_005f2exp_005fp)
566 #[link_name = "__gmpz_congruent_2exp_p"]
mpz_congruent_2exp_p(n: mpz_srcptr, c: mpz_srcptr, b: bitcnt_t) -> c_int567 pub fn mpz_congruent_2exp_p(n: mpz_srcptr, c: mpz_srcptr, b: bitcnt_t) -> c_int;
568
569 // Exponentiation Functions
570
571 /// See: [`mpz_powm`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fpowm)
572 #[link_name = "__gmpz_powm"]
mpz_powm(rop: mpz_ptr, base: mpz_srcptr, exp: mpz_srcptr, modu: mpz_srcptr)573 pub fn mpz_powm(rop: mpz_ptr, base: mpz_srcptr, exp: mpz_srcptr, modu: mpz_srcptr);
574 /// See: [`mpz_powm_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fpowm_005fui)
575 #[link_name = "__gmpz_powm_ui"]
mpz_powm_ui(rop: mpz_ptr, base: mpz_srcptr, exp: c_ulong, modu: mpz_srcptr)576 pub fn mpz_powm_ui(rop: mpz_ptr, base: mpz_srcptr, exp: c_ulong, modu: mpz_srcptr);
577 /// See: [`mpz_powm_sec`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fpowm_005fsec)
578 #[link_name = "__gmpz_powm_sec"]
mpz_powm_sec(rop: mpz_ptr, base: mpz_srcptr, exp: mpz_srcptr, modu: mpz_srcptr)579 pub fn mpz_powm_sec(rop: mpz_ptr, base: mpz_srcptr, exp: mpz_srcptr, modu: mpz_srcptr);
580 /// See: [`mpz_pow_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fpow_005fui)
581 #[link_name = "__gmpz_pow_ui"]
mpz_pow_ui(rop: mpz_ptr, base: mpz_srcptr, exp: c_ulong)582 pub fn mpz_pow_ui(rop: mpz_ptr, base: mpz_srcptr, exp: c_ulong);
583 /// See: [`mpz_ui_pow_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fui_005fpow_005fui)
584 #[link_name = "__gmpz_ui_pow_ui"]
mpz_ui_pow_ui(rop: mpz_ptr, base: c_ulong, exp: c_ulong)585 pub fn mpz_ui_pow_ui(rop: mpz_ptr, base: c_ulong, exp: c_ulong);
586
587 // Root Extraction Functions
588
589 /// See: [`mpz_root`](../C/GMP/constant.Integer_Functions.html#index-mpz_005froot)
590 #[link_name = "__gmpz_root"]
mpz_root(rop: mpz_ptr, op: mpz_srcptr, n: c_ulong) -> c_int591 pub fn mpz_root(rop: mpz_ptr, op: mpz_srcptr, n: c_ulong) -> c_int;
592 /// See: [`mpz_rootrem`](../C/GMP/constant.Integer_Functions.html#index-mpz_005frootrem)
593 #[link_name = "__gmpz_rootrem"]
mpz_rootrem(root: mpz_ptr, rem: mpz_ptr, op: mpz_srcptr, n: c_ulong)594 pub fn mpz_rootrem(root: mpz_ptr, rem: mpz_ptr, op: mpz_srcptr, n: c_ulong);
595 /// See: [`mpz_sqrt`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsqrt)
596 #[link_name = "__gmpz_sqrt"]
mpz_sqrt(rop: mpz_ptr, op: mpz_srcptr)597 pub fn mpz_sqrt(rop: mpz_ptr, op: mpz_srcptr);
598 /// See: [`mpz_sqrtrem`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsqrtrem)
599 #[link_name = "__gmpz_sqrtrem"]
mpz_sqrtrem(rop1: mpz_ptr, rop2: mpz_ptr, op: mpz_srcptr)600 pub fn mpz_sqrtrem(rop1: mpz_ptr, rop2: mpz_ptr, op: mpz_srcptr);
601 /// See: [`mpz_perfect_power_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fperfect_005fpower_005fp)
602 #[link_name = "__gmpz_perfect_power_p"]
mpz_perfect_power_p(op: mpz_srcptr) -> c_int603 pub fn mpz_perfect_power_p(op: mpz_srcptr) -> c_int;
604 }
605 /// See: [`mpz_perfect_square_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fperfect_005fsquare_005fp)
606 #[inline]
mpz_perfect_square_p(op: mpz_srcptr) -> c_int607 pub unsafe extern "C" fn mpz_perfect_square_p(op: mpz_srcptr) -> c_int {
608 let op_size = unsafe { (*op).size };
609 if op_size > 0 {
610 unsafe { mpn_perfect_square_p((*op).d.as_ptr(), op_size.into()) }
611 } else if op_size >= 0 {
612 1
613 } else {
614 0
615 }
616 }
617
618 // Number Theoretic Functions
619
620 extern "C" {
621 /// See: [`mpz_probab_prime_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fprobab_005fprime_005fp)
622 #[link_name = "__gmpz_probab_prime_p"]
mpz_probab_prime_p(n: mpz_srcptr, reps: c_int) -> c_int623 pub fn mpz_probab_prime_p(n: mpz_srcptr, reps: c_int) -> c_int;
624 /// See: [`mpz_nextprime`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fnextprime)
625 #[link_name = "__gmpz_nextprime"]
mpz_nextprime(rop: mpz_ptr, op: mpz_srcptr)626 pub fn mpz_nextprime(rop: mpz_ptr, op: mpz_srcptr);
627 /// See: [`mpz_gcd`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fgcd)
628 #[link_name = "__gmpz_gcd"]
mpz_gcd(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)629 pub fn mpz_gcd(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
630 /// See: [`mpz_gcd_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fgcd_005fui)
631 #[link_name = "__gmpz_gcd_ui"]
mpz_gcd_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong) -> c_ulong632 pub fn mpz_gcd_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong) -> c_ulong;
633 /// See: [`mpz_gcdext`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fgcdext)
634 #[link_name = "__gmpz_gcdext"]
mpz_gcdext(g: mpz_ptr, s: mpz_ptr, t: mpz_ptr, a: mpz_srcptr, b: mpz_srcptr)635 pub fn mpz_gcdext(g: mpz_ptr, s: mpz_ptr, t: mpz_ptr, a: mpz_srcptr, b: mpz_srcptr);
636 /// See: [`mpz_lcm`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flcm)
637 #[link_name = "__gmpz_lcm"]
mpz_lcm(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)638 pub fn mpz_lcm(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
639 /// See: [`mpz_lcm_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flcm_005fui)
640 #[link_name = "__gmpz_lcm_ui"]
mpz_lcm_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong)641 pub fn mpz_lcm_ui(rop: mpz_ptr, op1: mpz_srcptr, op2: c_ulong);
642 /// See: [`mpz_invert`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finvert)
643 #[link_name = "__gmpz_invert"]
mpz_invert(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr) -> c_int644 pub fn mpz_invert(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr) -> c_int;
645 /// See: [`mpz_jacobi`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fjacobi)
646 #[link_name = "__gmpz_jacobi"]
mpz_jacobi(a: mpz_srcptr, b: mpz_srcptr) -> c_int647 pub fn mpz_jacobi(a: mpz_srcptr, b: mpz_srcptr) -> c_int;
648 }
649 /// See: [`mpz_legendre`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flegendre)
650 #[inline]
mpz_legendre(a: mpz_srcptr, p: mpz_srcptr) -> c_int651 pub unsafe extern "C" fn mpz_legendre(a: mpz_srcptr, p: mpz_srcptr) -> c_int {
652 unsafe { mpz_jacobi(a, p) }
653 }
654 /// See: [`mpz_kronecker`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fkronecker)
655 #[inline]
mpz_kronecker(a: mpz_srcptr, b: mpz_srcptr) -> c_int656 pub unsafe extern "C" fn mpz_kronecker(a: mpz_srcptr, b: mpz_srcptr) -> c_int {
657 unsafe { mpz_jacobi(a, b) }
658 }
659 extern "C" {
660 /// See: [`mpz_kronecker_si`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fkronecker_005fsi)
661 #[link_name = "__gmpz_kronecker_si"]
mpz_kronecker_si(a: mpz_srcptr, b: c_long) -> c_int662 pub fn mpz_kronecker_si(a: mpz_srcptr, b: c_long) -> c_int;
663 /// See: [`mpz_kronecker_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fkronecker_005fui)
664 #[link_name = "__gmpz_kronecker_ui"]
mpz_kronecker_ui(a: mpz_srcptr, b: c_ulong) -> c_int665 pub fn mpz_kronecker_ui(a: mpz_srcptr, b: c_ulong) -> c_int;
666 /// See: [`mpz_si_kronecker`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsi_005fkronecker)
667 #[link_name = "__gmpz_si_kronecker"]
mpz_si_kronecker(a: c_long, b: mpz_srcptr) -> c_int668 pub fn mpz_si_kronecker(a: c_long, b: mpz_srcptr) -> c_int;
669 /// See: [`mpz_ui_kronecker`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fui_005fkronecker)
670 #[link_name = "__gmpz_ui_kronecker"]
mpz_ui_kronecker(a: c_ulong, b: mpz_srcptr) -> c_int671 pub fn mpz_ui_kronecker(a: c_ulong, b: mpz_srcptr) -> c_int;
672 /// See: [`mpz_remove`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fremove)
673 #[link_name = "__gmpz_remove"]
mpz_remove(rop: mpz_ptr, op: mpz_srcptr, f: mpz_srcptr) -> bitcnt_t674 pub fn mpz_remove(rop: mpz_ptr, op: mpz_srcptr, f: mpz_srcptr) -> bitcnt_t;
675 /// See: [`mpz_fac_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffac_005fui)
676 #[link_name = "__gmpz_fac_ui"]
mpz_fac_ui(rop: mpz_ptr, n: c_ulong)677 pub fn mpz_fac_ui(rop: mpz_ptr, n: c_ulong);
678 /// See: [`mpz_2fac_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005f2fac_005fui)
679 #[link_name = "__gmpz_2fac_ui"]
mpz_2fac_ui(rop: mpz_ptr, n: c_ulong)680 pub fn mpz_2fac_ui(rop: mpz_ptr, n: c_ulong);
681 /// See: [`mpz_mfac_uiui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fmfac_005fuiui)
682 #[link_name = "__gmpz_mfac_uiui"]
mpz_mfac_uiui(rop: mpz_ptr, n: c_ulong, m: c_ulong)683 pub fn mpz_mfac_uiui(rop: mpz_ptr, n: c_ulong, m: c_ulong);
684 /// See: [`mpz_primorial_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fprimorial_005fui)
685 #[link_name = "__gmpz_primorial_ui"]
mpz_primorial_ui(r: mpz_ptr, n: c_ulong)686 pub fn mpz_primorial_ui(r: mpz_ptr, n: c_ulong);
687 /// See: [`mpz_bin_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fbin_005fui)
688 #[link_name = "__gmpz_bin_ui"]
mpz_bin_ui(rop: mpz_ptr, n: mpz_srcptr, k: c_ulong)689 pub fn mpz_bin_ui(rop: mpz_ptr, n: mpz_srcptr, k: c_ulong);
690 /// See: [`mpz_bin_uiui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fbin_005fuiui)
691 #[link_name = "__gmpz_bin_uiui"]
mpz_bin_uiui(rop: mpz_ptr, n: c_ulong, k: c_ulong)692 pub fn mpz_bin_uiui(rop: mpz_ptr, n: c_ulong, k: c_ulong);
693 /// See: [`mpz_fib_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffib_005fui)
694 #[link_name = "__gmpz_fib_ui"]
mpz_fib_ui(f_n: mpz_ptr, n: c_ulong)695 pub fn mpz_fib_ui(f_n: mpz_ptr, n: c_ulong);
696 /// See: [`mpz_fib2_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffib2_005fui)
697 #[link_name = "__gmpz_fib2_ui"]
mpz_fib2_ui(f_n: mpz_ptr, fnsub1: mpz_ptr, n: c_ulong)698 pub fn mpz_fib2_ui(f_n: mpz_ptr, fnsub1: mpz_ptr, n: c_ulong);
699 /// See: [`mpz_lucnum_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flucnum_005fui)
700 #[link_name = "__gmpz_lucnum_ui"]
mpz_lucnum_ui(ln: mpz_ptr, n: c_ulong)701 pub fn mpz_lucnum_ui(ln: mpz_ptr, n: c_ulong);
702 /// See: [`mpz_lucnum2_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flucnum2_005fui)
703 #[link_name = "__gmpz_lucnum2_ui"]
mpz_lucnum2_ui(ln: mpz_ptr, lnsub1: mpz_ptr, n: c_ulong)704 pub fn mpz_lucnum2_ui(ln: mpz_ptr, lnsub1: mpz_ptr, n: c_ulong);
705
706 // Comparison Functions
707
708 /// See: [`mpz_cmp`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmp)
709 #[link_name = "__gmpz_cmp"]
mpz_cmp(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int710 pub fn mpz_cmp(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int;
711 /// See: [`mpz_cmp_d`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmp_005fd)
712 #[link_name = "__gmpz_cmp_d"]
mpz_cmp_d(op1: mpz_srcptr, op2: f64) -> c_int713 pub fn mpz_cmp_d(op1: mpz_srcptr, op2: f64) -> c_int;
714 /// See: [`mpz_cmp_si`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmp_005fsi)
715 #[link_name = "__gmpz_cmp_si"]
mpz_cmp_si(op1: mpz_srcptr, op2: c_long) -> c_int716 pub fn mpz_cmp_si(op1: mpz_srcptr, op2: c_long) -> c_int;
717 /// See: [`mpz_cmp_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmp_005fui)
718 #[link_name = "__gmpz_cmp_ui"]
mpz_cmp_ui(op1: mpz_srcptr, op2: c_ulong) -> c_int719 pub fn mpz_cmp_ui(op1: mpz_srcptr, op2: c_ulong) -> c_int;
720 /// See: [`mpz_cmpabs`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmpabs)
721 #[link_name = "__gmpz_cmpabs"]
mpz_cmpabs(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int722 pub fn mpz_cmpabs(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int;
723 /// See: [`mpz_cmpabs_d`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmpabs_005fd)
724 #[link_name = "__gmpz_cmpabs_d"]
mpz_cmpabs_d(op1: mpz_srcptr, op2: f64) -> c_int725 pub fn mpz_cmpabs_d(op1: mpz_srcptr, op2: f64) -> c_int;
726 /// See: [`mpz_cmpabs_ui`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcmpabs_005fui)
727 #[link_name = "__gmpz_cmpabs_ui"]
mpz_cmpabs_ui(op1: mpz_srcptr, op2: c_ulong) -> c_int728 pub fn mpz_cmpabs_ui(op1: mpz_srcptr, op2: c_ulong) -> c_int;
729 }
730 /// See: [`mpz_sgn`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsgn)
731 #[inline]
mpz_sgn(op: mpz_srcptr) -> c_int732 pub unsafe extern "C" fn mpz_sgn(op: mpz_srcptr) -> c_int {
733 match unsafe { (*op).size }.cmp(&0) {
734 Ordering::Less => -1,
735 Ordering::Equal => 0,
736 Ordering::Greater => 1,
737 }
738 }
739 extern "C" {
740 /// See: [`mpz_and`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fand)
741 #[link_name = "__gmpz_and"]
mpz_and(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)742 pub fn mpz_and(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
743 /// See: [`mpz_ior`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fior)
744 #[link_name = "__gmpz_ior"]
mpz_ior(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)745 pub fn mpz_ior(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
746 /// See: [`mpz_xor`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fxor)
747 #[link_name = "__gmpz_xor"]
mpz_xor(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr)748 pub fn mpz_xor(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
749 /// See: [`mpz_com`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcom)
750 #[link_name = "__gmpz_com"]
mpz_com(rop: mpz_ptr, op: mpz_srcptr)751 pub fn mpz_com(rop: mpz_ptr, op: mpz_srcptr);
752 }
753 /// See: [`mpz_popcount`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fpopcount)
754 #[inline]
mpz_popcount(op: mpz_srcptr) -> bitcnt_t755 pub unsafe extern "C" fn mpz_popcount(op: mpz_srcptr) -> bitcnt_t {
756 let size = unsafe { (*op).size };
757 match size.cmp(&0) {
758 Ordering::Less => !0,
759 Ordering::Equal => 0,
760 Ordering::Greater => unsafe { mpn_popcount((*op).d.as_ptr(), size.into()) },
761 }
762 }
763 extern "C" {
764 /// See: [`mpz_hamdist`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fhamdist)
765 #[link_name = "__gmpz_hamdist"]
mpz_hamdist(op1: mpz_srcptr, op2: mpz_srcptr) -> bitcnt_t766 pub fn mpz_hamdist(op1: mpz_srcptr, op2: mpz_srcptr) -> bitcnt_t;
767 /// See: [`mpz_scan0`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fscan0)
768 #[link_name = "__gmpz_scan0"]
mpz_scan0(op: mpz_srcptr, starting_bit: bitcnt_t) -> bitcnt_t769 pub fn mpz_scan0(op: mpz_srcptr, starting_bit: bitcnt_t) -> bitcnt_t;
770 /// See: [`mpz_scan1`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fscan1)
771 #[link_name = "__gmpz_scan1"]
mpz_scan1(op: mpz_srcptr, starting_bit: bitcnt_t) -> bitcnt_t772 pub fn mpz_scan1(op: mpz_srcptr, starting_bit: bitcnt_t) -> bitcnt_t;
773 /// See: [`mpz_setbit`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsetbit)
774 #[link_name = "__gmpz_setbit"]
mpz_setbit(rop: mpz_ptr, bit_index: bitcnt_t)775 pub fn mpz_setbit(rop: mpz_ptr, bit_index: bitcnt_t);
776 /// See: [`mpz_clrbit`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fclrbit)
777 #[link_name = "__gmpz_clrbit"]
mpz_clrbit(rop: mpz_ptr, bit_index: bitcnt_t)778 pub fn mpz_clrbit(rop: mpz_ptr, bit_index: bitcnt_t);
779 /// See: [`mpz_combit`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fcombit)
780 #[link_name = "__gmpz_combit"]
mpz_combit(rop: mpz_ptr, bit_index: bitcnt_t)781 pub fn mpz_combit(rop: mpz_ptr, bit_index: bitcnt_t);
782 /// See: [`mpz_tstbit`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ftstbit)
783 #[link_name = "__gmpz_tstbit"]
mpz_tstbit(op: mpz_srcptr, bit_index: bitcnt_t) -> c_int784 pub fn mpz_tstbit(op: mpz_srcptr, bit_index: bitcnt_t) -> c_int;
785
786 // Input and Ouput Functions
787
788 /// See: [`mpz_out_str`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fout_005fstr)
789 #[link_name = "__gmpz_out_str"]
mpz_out_str(stream: *mut FILE, base: c_int, op: mpz_srcptr) -> usize790 pub fn mpz_out_str(stream: *mut FILE, base: c_int, op: mpz_srcptr) -> usize;
791 /// See: [`mpz_inp_str`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finp_005fstr)
792 #[link_name = "__gmpz_inp_str"]
mpz_inp_str(rop: mpz_ptr, stream: *mut FILE, base: c_int) -> usize793 pub fn mpz_inp_str(rop: mpz_ptr, stream: *mut FILE, base: c_int) -> usize;
794 /// See: [`mpz_out_raw`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fout_005fraw)
795 #[link_name = "__gmpz_out_raw"]
mpz_out_raw(stream: *mut FILE, op: mpz_srcptr) -> usize796 pub fn mpz_out_raw(stream: *mut FILE, op: mpz_srcptr) -> usize;
797 /// See: [`mpz_inp_raw`](../C/GMP/constant.Integer_Functions.html#index-mpz_005finp_005fraw)
798 #[link_name = "__gmpz_inp_raw"]
mpz_inp_raw(rop: mpz_ptr, stream: *mut FILE) -> usize799 pub fn mpz_inp_raw(rop: mpz_ptr, stream: *mut FILE) -> usize;
800
801 // Random Number Functions
802
803 /// See: [`mpz_urandomb`](../C/GMP/constant.Integer_Functions.html#index-mpz_005furandomb)
804 #[link_name = "__gmpz_urandomb"]
mpz_urandomb(rop: mpz_ptr, state: randstate_ptr, n: bitcnt_t)805 pub fn mpz_urandomb(rop: mpz_ptr, state: randstate_ptr, n: bitcnt_t);
806 /// See: [`mpz_urandomm`](../C/GMP/constant.Integer_Functions.html#index-mpz_005furandomm)
807 #[link_name = "__gmpz_urandomm"]
mpz_urandomm(rop: mpz_ptr, state: randstate_ptr, n: mpz_srcptr)808 pub fn mpz_urandomm(rop: mpz_ptr, state: randstate_ptr, n: mpz_srcptr);
809 /// See: [`mpz_rrandomb`](../C/GMP/constant.Integer_Functions.html#index-mpz_005frrandomb)
810 #[link_name = "__gmpz_rrandomb"]
mpz_rrandomb(rop: mpz_ptr, state: randstate_ptr, n: bitcnt_t)811 pub fn mpz_rrandomb(rop: mpz_ptr, state: randstate_ptr, n: bitcnt_t);
812 /// See: [`mpz_random2`](../C/GMP/constant.Integer_Functions.html#index-mpz_005frandom2)
813 #[link_name = "__gmpz_random2"]
mpz_random2(rop: mpz_ptr, max_size: size_t)814 pub fn mpz_random2(rop: mpz_ptr, max_size: size_t);
815
816 // Integer Import and Export
817
818 /// See: [`mpz_import`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fimport)
819 #[link_name = "__gmpz_import"]
mpz_import( rop: mpz_ptr, count: usize, order: c_int, size: usize, endian: c_int, nails: usize, op: *const c_void, )820 pub fn mpz_import(
821 rop: mpz_ptr,
822 count: usize,
823 order: c_int,
824 size: usize,
825 endian: c_int,
826 nails: usize,
827 op: *const c_void,
828 );
829 /// See: [`mpz_export`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fexport)
830 #[link_name = "__gmpz_export"]
mpz_export( rop: *mut c_void, countp: *mut usize, order: c_int, size: usize, endian: c_int, nails: usize, op: mpz_srcptr, ) -> *mut c_void831 pub fn mpz_export(
832 rop: *mut c_void,
833 countp: *mut usize,
834 order: c_int,
835 size: usize,
836 endian: c_int,
837 nails: usize,
838 op: mpz_srcptr,
839 ) -> *mut c_void;
840 }
841
842 // Miscellaneous Functions
843
844 macro_rules! mpz_fits {
845 { $(#[$attr:meta])* fn $name:ident($max:expr); } => {
846 #[cfg(not(nails))]
847 $(#[$attr])*
848 #[inline]
849 pub unsafe extern "C" fn $name(op: mpz_srcptr) -> c_int {
850 let n = unsafe { (*op).size };
851 let p = unsafe { (*op).d }.as_ptr();
852 let fits = n == 0 || (n == 1 && unsafe { *p } <= limb_t::from($max));
853 if fits {
854 1
855 } else {
856 0
857 }
858 }
859 #[cfg(nails)]
860 $(#[$attr])*
861 #[inline]
862 pub unsafe extern "C" fn $name(op: mpz_srcptr) -> c_int {
863 let n = (*op).size;
864 let p = (*op).d;
865 let fits = n == 0 || (n == 1 && (*p) <= limb_t::from($max))
866 || (n == 2
867 && (*(p.offset(1))) <= limb_t::from($max) >> NUMB_BITS);
868 if fits {
869 1
870 } else {
871 0
872 }
873 }
874 }
875 }
876 mpz_fits! {
877 /// See: [`mpz_fits_ulong_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffits_005fulong_005fp)
878 fn mpz_fits_ulong_p(c_ulong::max_value());
879 }
880 extern "C" {
881 /// See: [`mpz_fits_slong_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffits_005fslong_005fp)
882 #[link_name = "__gmpz_fits_slong_p"]
mpz_fits_slong_p(op: mpz_srcptr) -> c_int883 pub fn mpz_fits_slong_p(op: mpz_srcptr) -> c_int;
884 }
885 mpz_fits! {
886 /// See: [`mpz_fits_uint_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffits_005fuint_005fp)
887 fn mpz_fits_uint_p(c_uint::max_value());
888 }
889 extern "C" {
890 /// See: [`mpz_fits_sint_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffits_005fsint_005fp)
891 #[link_name = "__gmpz_fits_sint_p"]
mpz_fits_sint_p(op: mpz_srcptr) -> c_int892 pub fn mpz_fits_sint_p(op: mpz_srcptr) -> c_int;
893 }
894 mpz_fits! {
895 /// See: [`mpz_fits_ushort_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffits_005fushort_005fp)
896 fn mpz_fits_ushort_p(c_ushort::max_value());
897 }
898 extern "C" {
899 /// See: [`mpz_fits_sshort_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005ffits_005fsshort_005fp)
900 #[link_name = "__gmpz_fits_sshort_p"]
mpz_fits_sshort_p(op: mpz_srcptr) -> c_int901 pub fn mpz_fits_sshort_p(op: mpz_srcptr) -> c_int;
902 }
903 /// See: [`mpz_odd_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fodd_005fp)
904 #[inline]
mpz_odd_p(op: mpz_srcptr) -> c_int905 pub unsafe extern "C" fn mpz_odd_p(op: mpz_srcptr) -> c_int {
906 if unsafe { (*op).size } == 0 {
907 0
908 } else {
909 1 & unsafe { *(*op).d.as_ptr() } as c_int
910 }
911 }
912 /// See: [`mpz_even_p`](../C/GMP/constant.Integer_Functions.html#index-mpz_005feven_005fp)
913 #[inline]
mpz_even_p(op: mpz_srcptr) -> c_int914 pub unsafe extern "C" fn mpz_even_p(op: mpz_srcptr) -> c_int {
915 if unsafe { mpz_odd_p(op) } == 0 {
916 1
917 } else {
918 0
919 }
920 }
921 extern "C" {
922 /// See: [`mpz_sizeinbase`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsizeinbase)
923 #[link_name = "__gmpz_sizeinbase"]
mpz_sizeinbase(arg1: mpz_srcptr, arg2: c_int) -> usize924 pub fn mpz_sizeinbase(arg1: mpz_srcptr, arg2: c_int) -> usize;
925
926 // Special Functions
927
928 /// See: [`_mpz_realloc`](../C/GMP/constant.Integer_Functions.html#index-_005fmpz_005frealloc)
929 #[link_name = "__gmpz_realloc"]
_mpz_realloc(integer: mpz_ptr, new_alloc: size_t) -> *mut c_void930 pub fn _mpz_realloc(integer: mpz_ptr, new_alloc: size_t) -> *mut c_void;
931 }
932 /// See: [`mpz_getlimbn`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fgetlimbn)
933 #[inline]
mpz_getlimbn(op: mpz_srcptr, n: size_t) -> limb_t934 pub unsafe extern "C" fn mpz_getlimbn(op: mpz_srcptr, n: size_t) -> limb_t {
935 if n >= 0 && n < size_t::from(unsafe { (*op).size }.abs()) {
936 unsafe { *((*op).d.as_ptr().offset(n as isize)) }
937 } else {
938 0
939 }
940 }
941 /// See: [`mpz_size`](../C/GMP/constant.Integer_Functions.html#index-mpz_005fsize)
942 #[inline]
mpz_size(op: mpz_srcptr) -> usize943 pub unsafe extern "C" fn mpz_size(op: mpz_srcptr) -> usize {
944 unsafe { (*op).size }.abs() as usize
945 }
946 extern "C" {
947 /// See: [`mpz_limbs_read`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flimbs_005fread)
948 #[link_name = "__gmpz_limbs_read"]
mpz_limbs_read(x: mpz_srcptr) -> mp_srcptr949 pub fn mpz_limbs_read(x: mpz_srcptr) -> mp_srcptr;
950 /// See: [`mpz_limbs_write`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flimbs_005fwrite)
951 #[link_name = "__gmpz_limbs_write"]
mpz_limbs_write(x: mpz_ptr, n: size_t) -> mp_ptr952 pub fn mpz_limbs_write(x: mpz_ptr, n: size_t) -> mp_ptr;
953 /// See: [`mpz_limbs_modify`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flimbs_005fmodify)
954 #[link_name = "__gmpz_limbs_modify"]
mpz_limbs_modify(x: mpz_ptr, n: size_t) -> mp_ptr955 pub fn mpz_limbs_modify(x: mpz_ptr, n: size_t) -> mp_ptr;
956 /// See: [`mpz_limbs_finish`](../C/GMP/constant.Integer_Functions.html#index-mpz_005flimbs_005ffinish)
957 #[link_name = "__gmpz_limbs_finish"]
mpz_limbs_finish(x: mpz_ptr, s: size_t)958 pub fn mpz_limbs_finish(x: mpz_ptr, s: size_t);
959 /// See: [`mpz_roinit_n`](../C/GMP/constant.Integer_Functions.html#index-mpz_005froinit_005fn)
960 #[link_name = "__gmpz_roinit_n"]
mpz_roinit_n(x: mpz_ptr, xp: mp_srcptr, xs: size_t) -> mpz_srcptr961 pub fn mpz_roinit_n(x: mpz_ptr, xp: mp_srcptr, xs: size_t) -> mpz_srcptr;
962 }
963 /// See: [`MPZ_ROINIT_N`](../C/GMP/constant.Integer_Functions.html#index-MPZ_005fROINIT_005fN)
964 ///
965 /// Note that this function is not currently `extern "C"` because such
966 /// functions cannot be const functions, and this function is intended
967 /// primarily for constant values. The function will be changed to
968 /// `extern "C"` once such functions can be const functions.
969 #[inline]
MPZ_ROINIT_N(xp: mp_ptr, xs: size_t) -> mpz_t970 pub const unsafe fn MPZ_ROINIT_N(xp: mp_ptr, xs: size_t) -> mpz_t {
971 mpz_t {
972 alloc: 0,
973 size: xs as c_int,
974 d: unsafe { NonNull::new_unchecked(xp) },
975 }
976 }
977
978 // Rational numbers
979
980 extern "C" {
981 /// See: [`mpq_canonicalize`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fcanonicalize)
982 #[link_name = "__gmpq_canonicalize"]
mpq_canonicalize(op: mpq_ptr)983 pub fn mpq_canonicalize(op: mpq_ptr);
984
985 // Initialization and Assignment Functions
986
987 /// See: [`mpq_init`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005finit)
988 #[link_name = "__gmpq_init"]
mpq_init(x: mpq_ptr)989 pub fn mpq_init(x: mpq_ptr);
990 /// See: [`mpq_inits`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005finits)
991 #[link_name = "__gmpq_inits"]
mpq_inits(x: mpq_ptr, ...)992 pub fn mpq_inits(x: mpq_ptr, ...);
993 /// See: [`mpq_clear`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fclear)
994 #[link_name = "__gmpq_clear"]
mpq_clear(x: mpq_ptr)995 pub fn mpq_clear(x: mpq_ptr);
996 /// See: [`mpq_clears`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fclears)
997 #[link_name = "__gmpq_clears"]
mpq_clears(x: mpq_ptr, ...)998 pub fn mpq_clears(x: mpq_ptr, ...);
999 /// See: [`mpq_set`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset)
1000 #[link_name = "__gmpq_set"]
mpq_set(rop: mpq_ptr, op: mpq_srcptr)1001 pub fn mpq_set(rop: mpq_ptr, op: mpq_srcptr);
1002 /// See: [`mpq_set_z`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fz)
1003 #[link_name = "__gmpq_set_z"]
mpq_set_z(rop: mpq_ptr, op: mpz_srcptr)1004 pub fn mpq_set_z(rop: mpq_ptr, op: mpz_srcptr);
1005 /// See: [`mpq_set_ui`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fui)
1006 #[link_name = "__gmpq_set_ui"]
mpq_set_ui(rop: mpq_ptr, op1: c_ulong, op2: c_ulong)1007 pub fn mpq_set_ui(rop: mpq_ptr, op1: c_ulong, op2: c_ulong);
1008 /// See: [`mpq_set_si`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fsi)
1009 #[link_name = "__gmpq_set_si"]
mpq_set_si(rop: mpq_ptr, op1: c_long, op2: c_ulong)1010 pub fn mpq_set_si(rop: mpq_ptr, op1: c_long, op2: c_ulong);
1011 /// See: [`mpq_set_str`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fstr)
1012 #[link_name = "__gmpq_set_str"]
mpq_set_str(rop: mpq_ptr, str: *const c_char, base: c_int) -> c_int1013 pub fn mpq_set_str(rop: mpq_ptr, str: *const c_char, base: c_int) -> c_int;
1014 /// See: [`mpq_swap`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fswap)
1015 #[link_name = "__gmpq_swap"]
mpq_swap(rop1: mpq_ptr, rop2: mpq_ptr)1016 pub fn mpq_swap(rop1: mpq_ptr, rop2: mpq_ptr);
1017
1018 // Conversion Functions
1019
1020 /// See: [`mpq_get_d`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fget_005fd)
1021 #[link_name = "__gmpq_get_d"]
mpq_get_d(op: mpq_srcptr) -> f641022 pub fn mpq_get_d(op: mpq_srcptr) -> f64;
1023 /// See: [`mpq_set_d`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fd)
1024 #[link_name = "__gmpq_set_d"]
mpq_set_d(rop: mpq_ptr, op: f64)1025 pub fn mpq_set_d(rop: mpq_ptr, op: f64);
1026 /// See: [`mpq_set_f`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005ff)
1027 #[link_name = "__gmpq_set_f"]
mpq_set_f(rop: mpq_ptr, op: mpf_srcptr)1028 pub fn mpq_set_f(rop: mpq_ptr, op: mpf_srcptr);
1029 /// See: [`mpq_get_str`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fget_005fstr)
1030 #[link_name = "__gmpq_get_str"]
mpq_get_str(str: *mut c_char, base: c_int, op: mpq_srcptr) -> *mut c_char1031 pub fn mpq_get_str(str: *mut c_char, base: c_int, op: mpq_srcptr) -> *mut c_char;
1032
1033 // Arithmetic Functions
1034
1035 /// See: [`mpq_add`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fadd)
1036 #[link_name = "__gmpq_add"]
mpq_add(sum: mpq_ptr, addend1: mpq_srcptr, addend2: mpq_srcptr)1037 pub fn mpq_add(sum: mpq_ptr, addend1: mpq_srcptr, addend2: mpq_srcptr);
1038 /// See: [`mpq_sub`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fsub)
1039 #[link_name = "__gmpq_sub"]
mpq_sub(difference: mpq_ptr, minuend: mpq_srcptr, subtrahend: mpq_srcptr)1040 pub fn mpq_sub(difference: mpq_ptr, minuend: mpq_srcptr, subtrahend: mpq_srcptr);
1041 /// See: [`mpq_mul`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fmul)
1042 #[link_name = "__gmpq_mul"]
mpq_mul(product: mpq_ptr, multiplier: mpq_srcptr, multiplicand: mpq_srcptr)1043 pub fn mpq_mul(product: mpq_ptr, multiplier: mpq_srcptr, multiplicand: mpq_srcptr);
1044 /// See: [`mpq_mul_2exp`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fmul_005f2exp)
1045 #[link_name = "__gmpq_mul_2exp"]
mpq_mul_2exp(rop: mpq_ptr, op1: mpq_srcptr, op2: bitcnt_t)1046 pub fn mpq_mul_2exp(rop: mpq_ptr, op1: mpq_srcptr, op2: bitcnt_t);
1047 /// See: [`mpq_div`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fdiv)
1048 #[link_name = "__gmpq_div"]
mpq_div(quotient: mpq_ptr, dividend: mpq_srcptr, divisor: mpq_srcptr)1049 pub fn mpq_div(quotient: mpq_ptr, dividend: mpq_srcptr, divisor: mpq_srcptr);
1050 /// See: [`mpq_div_2exp`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fdiv_005f2exp)
1051 #[link_name = "__gmpq_div_2exp"]
mpq_div_2exp(rop: mpq_ptr, op1: mpq_srcptr, op2: bitcnt_t)1052 pub fn mpq_div_2exp(rop: mpq_ptr, op1: mpq_srcptr, op2: bitcnt_t);
1053 }
1054 /// See: [`mpq_neg`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fneg)
1055 #[inline]
mpq_neg(negated_operand: mpq_ptr, operand: mpq_srcptr)1056 pub unsafe extern "C" fn mpq_neg(negated_operand: mpq_ptr, operand: mpq_srcptr) {
1057 if negated_operand as mpq_srcptr != operand {
1058 unsafe { mpq_set(negated_operand, operand) };
1059 }
1060 unsafe {
1061 (*negated_operand).num.size = -(*negated_operand).num.size;
1062 }
1063 }
1064 /// See: [`mpq_abs`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fabs)
1065 #[inline]
mpq_abs(rop: mpq_ptr, op: mpq_srcptr)1066 pub unsafe extern "C" fn mpq_abs(rop: mpq_ptr, op: mpq_srcptr) {
1067 if rop as mpq_srcptr != op {
1068 unsafe {
1069 mpq_set(rop, op);
1070 }
1071 }
1072 unsafe {
1073 (*rop).num.size = (*rop).num.size.abs();
1074 }
1075 }
1076 extern "C" {
1077 /// See: [`mpq_inv`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005finv)
1078 #[link_name = "__gmpq_inv"]
mpq_inv(inverted_number: mpq_ptr, number: mpq_srcptr)1079 pub fn mpq_inv(inverted_number: mpq_ptr, number: mpq_srcptr);
1080
1081 // Comparison Functions
1082
1083 /// See: [`mpq_cmp`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fcmp)
1084 #[link_name = "__gmpq_cmp"]
mpq_cmp(op1: mpq_srcptr, op2: mpq_srcptr) -> c_int1085 pub fn mpq_cmp(op1: mpq_srcptr, op2: mpq_srcptr) -> c_int;
1086 /// See: [`mpq_cmp_z`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fcmp_005fz)
1087 #[link_name = "__gmpq_cmp_z"]
mpq_cmp_z(op1: mpq_srcptr, op2: mpz_srcptr) -> c_int1088 pub fn mpq_cmp_z(op1: mpq_srcptr, op2: mpz_srcptr) -> c_int;
1089 /// See: [`mpq_cmp_ui`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fcmp_005fui)
1090 #[link_name = "__gmpq_cmp_ui"]
mpq_cmp_ui(op1: mpq_srcptr, num2: c_ulong, den2: c_ulong) -> c_int1091 pub fn mpq_cmp_ui(op1: mpq_srcptr, num2: c_ulong, den2: c_ulong) -> c_int;
1092 /// See: [`mpq_cmp_si`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fcmp_005fsi)
1093 #[link_name = "__gmpq_cmp_si"]
mpq_cmp_si(op1: mpq_srcptr, num2: c_long, den2: c_ulong) -> c_int1094 pub fn mpq_cmp_si(op1: mpq_srcptr, num2: c_long, den2: c_ulong) -> c_int;
1095 }
1096 /// See: [`mpq_sgn`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fsgn)
1097 #[inline]
mpq_sgn(op: mpq_srcptr) -> c_int1098 pub unsafe extern "C" fn mpq_sgn(op: mpq_srcptr) -> c_int {
1099 match unsafe { (*op).num.size }.cmp(&0) {
1100 Ordering::Less => -1,
1101 Ordering::Equal => 0,
1102 Ordering::Greater => 1,
1103 }
1104 }
1105 extern "C" {
1106 /// See: [`mpq_equal`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fequal)
1107 #[link_name = "__gmpq_equal"]
mpq_equal(op1: mpq_srcptr, op2: mpq_srcptr) -> c_int1108 pub fn mpq_equal(op1: mpq_srcptr, op2: mpq_srcptr) -> c_int;
1109 }
1110
1111 // Applying Integer Functions to Rationals
1112
1113 /// See: [`mpq_numref`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fnumref)
1114 #[inline]
mpq_numref(op: mpq_ptr) -> mpz_ptr1115 pub unsafe extern "C" fn mpq_numref(op: mpq_ptr) -> mpz_ptr {
1116 op as mpz_ptr
1117 }
1118 /// Constant version of [`mpq_numref`](fn.mpq_numref.html).
1119 #[inline]
mpq_numref_const(op: mpq_srcptr) -> mpz_srcptr1120 pub unsafe extern "C" fn mpq_numref_const(op: mpq_srcptr) -> mpz_srcptr {
1121 op as mpz_srcptr
1122 }
1123 /// See: [`mpq_denref`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fdenref)
1124 #[inline]
mpq_denref(op: mpq_ptr) -> mpz_ptr1125 pub unsafe extern "C" fn mpq_denref(op: mpq_ptr) -> mpz_ptr {
1126 unsafe { (op as mpz_ptr).offset(1) }
1127 }
1128 /// Constant version of [`mpq_denref`](fn.mpq_denref.html).
1129 #[inline]
mpq_denref_const(op: mpq_srcptr) -> mpz_srcptr1130 pub unsafe extern "C" fn mpq_denref_const(op: mpq_srcptr) -> mpz_srcptr {
1131 unsafe { (op as mpz_srcptr).offset(1) }
1132 }
1133 extern "C" {
1134 /// See: [`mpq_get_num`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fget_005fnum)
1135 #[link_name = "__gmpq_get_num"]
mpq_get_num(numerator: mpz_ptr, rational: mpq_srcptr)1136 pub fn mpq_get_num(numerator: mpz_ptr, rational: mpq_srcptr);
1137 /// See: [`mpq_get_den`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fget_005fden)
1138 #[link_name = "__gmpq_get_den"]
mpq_get_den(denominator: mpz_ptr, rational: mpq_srcptr)1139 pub fn mpq_get_den(denominator: mpz_ptr, rational: mpq_srcptr);
1140 /// See: [`mpq_set_num`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fnum)
1141 #[link_name = "__gmpq_set_num"]
mpq_set_num(rational: mpq_ptr, denominator: mpz_srcptr)1142 pub fn mpq_set_num(rational: mpq_ptr, denominator: mpz_srcptr);
1143 /// See: [`mpq_set_den`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fset_005fden)
1144 #[link_name = "__gmpq_set_den"]
mpq_set_den(rational: mpq_ptr, numerator: mpz_srcptr)1145 pub fn mpq_set_den(rational: mpq_ptr, numerator: mpz_srcptr);
1146
1147 // Input and Output Functions
1148
1149 /// See: [`mpq_out_str`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fout_005fstr)
1150 #[link_name = "__gmpq_out_str"]
mpq_out_str(stream: *mut FILE, base: c_int, op: mpq_srcptr) -> usize1151 pub fn mpq_out_str(stream: *mut FILE, base: c_int, op: mpq_srcptr) -> usize;
1152 /// See: [`mpq_inp_str`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005finp_005fstr)
1153 #[link_name = "__gmpq_inp_str"]
mpq_inp_str(rop: mpq_ptr, stream: *mut FILE, base: c_int) -> usize1154 pub fn mpq_inp_str(rop: mpq_ptr, stream: *mut FILE, base: c_int) -> usize;
1155 }
1156
1157 // Floating-point numbers
1158
1159 // Initialization Functions
1160
1161 extern "C" {
1162 /// See: [`mpf_set_default_prec`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fdefault_005fprec)
1163 #[link_name = "__gmpf_set_default_prec"]
mpf_set_default_prec(prec: bitcnt_t)1164 pub fn mpf_set_default_prec(prec: bitcnt_t);
1165 /// See: [`mpf_get_default_prec`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fdefault_005fprec)
1166 #[link_name = "__gmpf_get_default_prec"]
mpf_get_default_prec() -> bitcnt_t1167 pub fn mpf_get_default_prec() -> bitcnt_t;
1168 /// See: [`mpf_init`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit)
1169 #[link_name = "__gmpf_init"]
mpf_init(x: mpf_ptr)1170 pub fn mpf_init(x: mpf_ptr);
1171 /// See: [`mpf_init2`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit2)
1172 #[link_name = "__gmpf_init2"]
mpf_init2(x: mpf_ptr, prec: bitcnt_t)1173 pub fn mpf_init2(x: mpf_ptr, prec: bitcnt_t);
1174 /// See: [`mpf_inits`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finits)
1175 #[link_name = "__gmpf_inits"]
mpf_inits(x: mpf_ptr, ...)1176 pub fn mpf_inits(x: mpf_ptr, ...);
1177 /// See: [`mpf_clear`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fclear)
1178 #[link_name = "__gmpf_clear"]
mpf_clear(x: mpf_ptr)1179 pub fn mpf_clear(x: mpf_ptr);
1180 /// See: [`mpf_clears`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fclears)
1181 #[link_name = "__gmpf_clears"]
mpf_clears(x: mpf_ptr, ...)1182 pub fn mpf_clears(x: mpf_ptr, ...);
1183 /// See: [`mpf_get_prec`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fprec)
1184 #[link_name = "__gmpf_get_prec"]
mpf_get_prec(op: mpf_srcptr) -> bitcnt_t1185 pub fn mpf_get_prec(op: mpf_srcptr) -> bitcnt_t;
1186 /// See: [`mpf_set_prec`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fprec)
1187 #[link_name = "__gmpf_set_prec"]
mpf_set_prec(rop: mpf_ptr, prec: bitcnt_t)1188 pub fn mpf_set_prec(rop: mpf_ptr, prec: bitcnt_t);
1189 /// See: [`mpf_set_prec_raw`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fprec_005fraw)
1190 #[link_name = "__gmpf_set_prec_raw"]
mpf_set_prec_raw(rop: mpf_ptr, prec: bitcnt_t)1191 pub fn mpf_set_prec_raw(rop: mpf_ptr, prec: bitcnt_t);
1192
1193 // Assignment Functions
1194
1195 /// See: [`mpf_set`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset)
1196 #[link_name = "__gmpf_set"]
mpf_set(rop: mpf_ptr, op: mpf_srcptr)1197 pub fn mpf_set(rop: mpf_ptr, op: mpf_srcptr);
1198 /// See: [`mpf_set_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fui)
1199 #[link_name = "__gmpf_set_ui"]
mpf_set_ui(rop: mpf_ptr, op: c_ulong)1200 pub fn mpf_set_ui(rop: mpf_ptr, op: c_ulong);
1201 /// See: [`mpf_set_si`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fsi)
1202 #[link_name = "__gmpf_set_si"]
mpf_set_si(rop: mpf_ptr, op: c_long)1203 pub fn mpf_set_si(rop: mpf_ptr, op: c_long);
1204 /// See: [`mpf_set_default_prec`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fdefault_005fprec)
1205 #[link_name = "__gmpf_set_d"]
mpf_set_d(rop: mpf_ptr, op: f64)1206 pub fn mpf_set_d(rop: mpf_ptr, op: f64);
1207 /// See: [`mpf_set_z`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fz)
1208 #[link_name = "__gmpf_set_z"]
mpf_set_z(rop: mpf_ptr, op: mpz_srcptr)1209 pub fn mpf_set_z(rop: mpf_ptr, op: mpz_srcptr);
1210 /// See: [`mpf_set_q`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fq)
1211 #[link_name = "__gmpf_set_q"]
mpf_set_q(rop: mpf_ptr, op: mpq_srcptr)1212 pub fn mpf_set_q(rop: mpf_ptr, op: mpq_srcptr);
1213 /// See: [`mpf_set_str`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fset_005fstr)
1214 #[link_name = "__gmpf_set_str"]
mpf_set_str(rop: mpf_ptr, str: *const c_char, base: c_int) -> c_int1215 pub fn mpf_set_str(rop: mpf_ptr, str: *const c_char, base: c_int) -> c_int;
1216 /// See: [`mpf_swap`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fswap)
1217 #[link_name = "__gmpf_swap"]
mpf_swap(rop1: mpf_ptr, rop2: mpf_ptr)1218 pub fn mpf_swap(rop1: mpf_ptr, rop2: mpf_ptr);
1219
1220 // Combined Initialization and Assignment Functions
1221
1222 /// See: [`mpf_init_set`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit_005fset)
1223 #[link_name = "__gmpf_init_set"]
mpf_init_set(rop: mpf_ptr, op: mpf_srcptr)1224 pub fn mpf_init_set(rop: mpf_ptr, op: mpf_srcptr);
1225 /// See: [`mpf_init_set_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit_005fset_005fui)
1226 #[link_name = "__gmpf_init_set_ui"]
mpf_init_set_ui(rop: mpf_ptr, op: c_ulong)1227 pub fn mpf_init_set_ui(rop: mpf_ptr, op: c_ulong);
1228 /// See: [`mpf_init_set_si`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit_005fset_005fsi)
1229 #[link_name = "__gmpf_init_set_si"]
mpf_init_set_si(rop: mpf_ptr, op: c_long)1230 pub fn mpf_init_set_si(rop: mpf_ptr, op: c_long);
1231 /// See: [`mpf_init_set_d`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit_005fset_005fd)
1232 #[link_name = "__gmpf_init_set_d"]
mpf_init_set_d(rop: mpf_ptr, op: f64)1233 pub fn mpf_init_set_d(rop: mpf_ptr, op: f64);
1234 /// See: [`mpf_init_set_str`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finit_005fset_005fstr)
1235 #[link_name = "__gmpf_init_set_str"]
mpf_init_set_str(rop: mpf_ptr, str: *const c_char, base: c_int) -> c_int1236 pub fn mpf_init_set_str(rop: mpf_ptr, str: *const c_char, base: c_int) -> c_int;
1237
1238 // Conversion Functions
1239
1240 /// See: [`mpf_get_d`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fd)
1241 #[link_name = "__gmpf_get_d"]
mpf_get_d(op: mpf_srcptr) -> f641242 pub fn mpf_get_d(op: mpf_srcptr) -> f64;
1243 /// See: [`mpf_get_d_2exp`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fd_005f2exp)
1244 #[link_name = "__gmpf_get_d_2exp"]
mpf_get_d_2exp(exp: *mut c_long, op: mpf_srcptr) -> f641245 pub fn mpf_get_d_2exp(exp: *mut c_long, op: mpf_srcptr) -> f64;
1246 /// See: [`mpf_get_si`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fsi)
1247 #[link_name = "__gmpf_get_si"]
mpf_get_si(op: mpf_srcptr) -> c_long1248 pub fn mpf_get_si(op: mpf_srcptr) -> c_long;
1249 /// See: [`mpf_get_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fui)
1250 #[link_name = "__gmpf_get_ui"]
mpf_get_ui(op: mpf_srcptr) -> c_ulong1251 pub fn mpf_get_ui(op: mpf_srcptr) -> c_ulong;
1252 /// See: [`mpf_get_str`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fget_005fstr)
1253 #[link_name = "__gmpf_get_str"]
mpf_get_str( str: *mut c_char, expptr: *mut exp_t, base: c_int, n_digits: usize, op: mpf_srcptr, ) -> *mut c_char1254 pub fn mpf_get_str(
1255 str: *mut c_char,
1256 expptr: *mut exp_t,
1257 base: c_int,
1258 n_digits: usize,
1259 op: mpf_srcptr,
1260 ) -> *mut c_char;
1261
1262 // Arithmetic Functions
1263
1264 /// See: [`mpf_add`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fadd)
1265 #[link_name = "__gmpf_add"]
mpf_add(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr)1266 pub fn mpf_add(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr);
1267 /// See: [`mpf_add_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fadd_005fui)
1268 #[link_name = "__gmpf_add_ui"]
mpf_add_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong)1269 pub fn mpf_add_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong);
1270 /// See: [`mpf_sub`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fsub)
1271 #[link_name = "__gmpf_sub"]
mpf_sub(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr)1272 pub fn mpf_sub(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr);
1273 /// See: [`mpf_ui_sub`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fui_005fsub)
1274 #[link_name = "__gmpf_ui_sub"]
mpf_ui_sub(rop: mpf_ptr, op1: c_ulong, op2: mpf_srcptr)1275 pub fn mpf_ui_sub(rop: mpf_ptr, op1: c_ulong, op2: mpf_srcptr);
1276 /// See: [`mpf_sub_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fsub_005fui)
1277 #[link_name = "__gmpf_sub_ui"]
mpf_sub_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong)1278 pub fn mpf_sub_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong);
1279 /// See: [`mpf_mul`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fmul)
1280 #[link_name = "__gmpf_mul"]
mpf_mul(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr)1281 pub fn mpf_mul(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr);
1282 /// See: [`mpf_mul_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fmul_005fui)
1283 #[link_name = "__gmpf_mul_ui"]
mpf_mul_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong)1284 pub fn mpf_mul_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong);
1285 /// See: [`mpf_div`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fdiv)
1286 #[link_name = "__gmpf_div"]
mpf_div(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr)1287 pub fn mpf_div(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr);
1288 /// See: [`mpf_ui_div`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fui_005fdiv)
1289 #[link_name = "__gmpf_ui_div"]
mpf_ui_div(rop: mpf_ptr, op1: c_ulong, op2: mpf_srcptr)1290 pub fn mpf_ui_div(rop: mpf_ptr, op1: c_ulong, op2: mpf_srcptr);
1291 /// See: [`mpf_div_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fdiv_005fui)
1292 #[link_name = "__gmpf_div_ui"]
mpf_div_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong)1293 pub fn mpf_div_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong);
1294 /// See: [`mpf_sqrt`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fsqrt)
1295 #[link_name = "__gmpf_sqrt"]
mpf_sqrt(rop: mpf_ptr, op: mpf_srcptr)1296 pub fn mpf_sqrt(rop: mpf_ptr, op: mpf_srcptr);
1297 /// See: [`mpf_sqrt_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fsqrt_005fui)
1298 #[link_name = "__gmpf_sqrt_ui"]
mpf_sqrt_ui(rop: mpf_ptr, op: c_ulong)1299 pub fn mpf_sqrt_ui(rop: mpf_ptr, op: c_ulong);
1300 /// See: [`mpf_pow_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fpow_005fui)
1301 #[link_name = "__gmpf_pow_ui"]
mpf_pow_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong)1302 pub fn mpf_pow_ui(rop: mpf_ptr, op1: mpf_srcptr, op2: c_ulong);
1303 /// See: [`mpf_neg`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fneg)
1304 #[link_name = "__gmpf_neg"]
mpf_neg(rop: mpf_ptr, op: mpf_srcptr)1305 pub fn mpf_neg(rop: mpf_ptr, op: mpf_srcptr);
1306 /// See: [`mpf_abs`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fabs)
1307 #[link_name = "__gmpf_abs"]
mpf_abs(rop: mpf_ptr, op: mpf_srcptr)1308 pub fn mpf_abs(rop: mpf_ptr, op: mpf_srcptr);
1309 /// See: [`mpf_mul_2exp`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fmul_005f2exp)
1310 #[link_name = "__gmpf_mul_2exp"]
mpf_mul_2exp(rop: mpf_ptr, op1: mpf_srcptr, op2: bitcnt_t)1311 pub fn mpf_mul_2exp(rop: mpf_ptr, op1: mpf_srcptr, op2: bitcnt_t);
1312 /// See: [`mpf_div_2exp`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fdiv_005f2exp)
1313 #[link_name = "__gmpf_div_2exp"]
mpf_div_2exp(rop: mpf_ptr, op1: mpf_srcptr, op2: bitcnt_t)1314 pub fn mpf_div_2exp(rop: mpf_ptr, op1: mpf_srcptr, op2: bitcnt_t);
1315
1316 // Comparison Functions
1317
1318 /// See: [`mpn_cmp`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcmp)
1319 #[link_name = "__gmpf_cmp"]
mpf_cmp(op1: mpf_srcptr, op2: mpf_srcptr) -> c_int1320 pub fn mpf_cmp(op1: mpf_srcptr, op2: mpf_srcptr) -> c_int;
1321 /// See: [`mpq_cmp_z`](../C/GMP/constant.Rational_Number_Functions.html#index-mpq_005fcmp_005fz)
1322 #[link_name = "__gmpf_cmp_z"]
mpf_cmp_z(op1: mpf_srcptr, op2: mpz_srcptr) -> c_int1323 pub fn mpf_cmp_z(op1: mpf_srcptr, op2: mpz_srcptr) -> c_int;
1324 /// See: [`mpf_cmp_d`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fcmp_005fd)
1325 #[link_name = "__gmpf_cmp_d"]
mpf_cmp_d(op1: mpf_srcptr, op2: f64) -> c_int1326 pub fn mpf_cmp_d(op1: mpf_srcptr, op2: f64) -> c_int;
1327 /// See: [`mpf_cmp_ui`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fcmp_005fui)
1328 #[link_name = "__gmpf_cmp_ui"]
mpf_cmp_ui(op1: mpf_srcptr, op2: c_ulong) -> c_int1329 pub fn mpf_cmp_ui(op1: mpf_srcptr, op2: c_ulong) -> c_int;
1330 /// See: [`mpf_cmp_si`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fcmp_005fsi)
1331 #[link_name = "__gmpf_cmp_si"]
mpf_cmp_si(op1: mpf_srcptr, op2: c_long) -> c_int1332 pub fn mpf_cmp_si(op1: mpf_srcptr, op2: c_long) -> c_int;
1333 /// See: [`mpf_eq`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005feq)
1334 #[link_name = "__gmpf_eq"]
mpf_eq(op1: mpf_srcptr, op2: mpf_srcptr, op3: bitcnt_t) -> c_int1335 pub fn mpf_eq(op1: mpf_srcptr, op2: mpf_srcptr, op3: bitcnt_t) -> c_int;
1336 /// See: [`mpf_reldiff`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005freldiff)
1337 #[link_name = "__gmpf_reldiff"]
mpf_reldiff(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr)1338 pub fn mpf_reldiff(rop: mpf_ptr, op1: mpf_srcptr, op2: mpf_srcptr);
1339 }
1340 /// See: [`mpf_sgn`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fsgn)
1341 #[inline]
mpf_sgn(op: mpf_srcptr) -> c_int1342 pub unsafe extern "C" fn mpf_sgn(op: mpf_srcptr) -> c_int {
1343 match unsafe { (*op).size }.cmp(&0) {
1344 Ordering::Less => -1,
1345 Ordering::Equal => 0,
1346 Ordering::Greater => 1,
1347 }
1348 }
1349
1350 // Input and Output Functions
1351
1352 extern "C" {
1353 /// See: [`mpf_out_str`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fout_005fstr)
1354 #[link_name = "__gmpf_out_str"]
mpf_out_str(stream: *mut FILE, base: c_int, n_digits: usize, op: mpf_srcptr) -> usize1355 pub fn mpf_out_str(stream: *mut FILE, base: c_int, n_digits: usize, op: mpf_srcptr) -> usize;
1356 /// See: [`mpf_inp_str`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finp_005fstr)
1357 #[link_name = "__gmpf_inp_str"]
mpf_inp_str(rop: mpf_ptr, stream: *mut FILE, base: c_int) -> usize1358 pub fn mpf_inp_str(rop: mpf_ptr, stream: *mut FILE, base: c_int) -> usize;
1359
1360 // Miscellaneous Functions
1361
1362 /// See: [`mpf_ceil`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005fceil)
1363 #[link_name = "__gmpf_ceil"]
mpf_ceil(rop: mpf_ptr, op: mpf_srcptr)1364 pub fn mpf_ceil(rop: mpf_ptr, op: mpf_srcptr);
1365 /// See: [`mpf_floor`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffloor)
1366 #[link_name = "__gmpf_floor"]
mpf_floor(rop: mpf_ptr, op: mpf_srcptr)1367 pub fn mpf_floor(rop: mpf_ptr, op: mpf_srcptr);
1368 /// See: [`mpf_trunc`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ftrunc)
1369 #[link_name = "__gmpf_trunc"]
mpf_trunc(rop: mpf_ptr, op: mpf_srcptr)1370 pub fn mpf_trunc(rop: mpf_ptr, op: mpf_srcptr);
1371 /// See: [`mpf_integer_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005finteger_005fp)
1372 #[link_name = "__gmpf_integer_p"]
mpf_integer_p(op: mpf_srcptr) -> c_int1373 pub fn mpf_integer_p(op: mpf_srcptr) -> c_int;
1374 /// See: [`mpf_fits_ulong_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffits_005fulong_005fp)
1375 #[link_name = "__gmpf_fits_ulong_p"]
mpf_fits_ulong_p(op: mpf_srcptr) -> c_int1376 pub fn mpf_fits_ulong_p(op: mpf_srcptr) -> c_int;
1377 /// See: [`mpf_fits_slong_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffits_005fslong_005fp)
1378 #[link_name = "__gmpf_fits_slong_p"]
mpf_fits_slong_p(op: mpf_srcptr) -> c_int1379 pub fn mpf_fits_slong_p(op: mpf_srcptr) -> c_int;
1380 /// See: [`mpf_fits_uint_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffits_005fuint_005fp)
1381 #[link_name = "__gmpf_fits_uint_p"]
mpf_fits_uint_p(op: mpf_srcptr) -> c_int1382 pub fn mpf_fits_uint_p(op: mpf_srcptr) -> c_int;
1383 /// See: [`mpf_fits_sint_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffits_005fsint_005fp)
1384 #[link_name = "__gmpf_fits_sint_p"]
mpf_fits_sint_p(op: mpf_srcptr) -> c_int1385 pub fn mpf_fits_sint_p(op: mpf_srcptr) -> c_int;
1386 /// See: [`mpf_fits_ushort_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffits_005fushort_005fp)
1387 #[link_name = "__gmpf_fits_ushort_p"]
mpf_fits_ushort_p(op: mpf_srcptr) -> c_int1388 pub fn mpf_fits_ushort_p(op: mpf_srcptr) -> c_int;
1389 /// See: [`mpf_fits_sshort_p`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005ffits_005fsshort_005fp)
1390 #[link_name = "__gmpf_fits_sshort_p"]
mpf_fits_sshort_p(op: mpf_srcptr) -> c_int1391 pub fn mpf_fits_sshort_p(op: mpf_srcptr) -> c_int;
1392 /// See: [`mpf_urandomb`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005furandomb)
1393 #[link_name = "__gmpf_urandomb"]
mpf_urandomb(rop: mpf_t, state: randstate_ptr, nbits: bitcnt_t)1394 pub fn mpf_urandomb(rop: mpf_t, state: randstate_ptr, nbits: bitcnt_t);
1395 /// See: [`mpf_random2`](../C/GMP/constant.Floating_point_Functions.html#index-mpf_005frandom2)
1396 #[link_name = "__gmpf_random2"]
mpf_random2(rop: mpf_ptr, max_size: size_t, exp: exp_t)1397 pub fn mpf_random2(rop: mpf_ptr, max_size: size_t, exp: exp_t);
1398 }
1399
1400 // Low-Level Functions
1401
1402 extern "C" {
1403 /// See: [`mpn_add_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fadd_005fn)
1404 #[link_name = "__gmpn_add_n"]
mpn_add_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> limb_t1405 pub fn mpn_add_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> limb_t;
1406 /// See: [`mpn_add_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fadd_005f1)
1407 #[link_name = "__gmpn_add_1"]
mpn_add_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t1408 pub fn mpn_add_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t;
1409 /// See: [`mpn_add`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fadd)
1410 #[link_name = "__gmpn_add"]
mpn_add(rp: mp_ptr, s1p: mp_srcptr, s1n: size_t, s2p: mp_srcptr, s2n: size_t) -> limb_t1411 pub fn mpn_add(rp: mp_ptr, s1p: mp_srcptr, s1n: size_t, s2p: mp_srcptr, s2n: size_t) -> limb_t;
1412 /// See: [`mpn_cnd_sub_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcnd_005fsub_005fn)
1413 #[link_name = "__gmpn_sub_n"]
mpn_sub_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> limb_t1414 pub fn mpn_sub_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> limb_t;
1415 /// See: [`mpn_sub_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsub_005f1)
1416 #[link_name = "__gmpn_sub_1"]
mpn_sub_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t1417 pub fn mpn_sub_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t;
1418 /// See: [`mpn_sub`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsub)
1419 #[link_name = "__gmpn_sub"]
mpn_sub(rp: mp_ptr, s1p: mp_srcptr, s1n: size_t, s2p: mp_srcptr, s2n: size_t) -> limb_t1420 pub fn mpn_sub(rp: mp_ptr, s1p: mp_srcptr, s1n: size_t, s2p: mp_srcptr, s2n: size_t) -> limb_t;
1421 /// See: [`mpn_neg`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fneg)
1422 #[link_name = "__gmpn_neg"]
mpn_neg(rp: mp_ptr, sp: mp_srcptr, n: size_t) -> limb_t1423 pub fn mpn_neg(rp: mp_ptr, sp: mp_srcptr, n: size_t) -> limb_t;
1424 /// See: [`mpn_mul_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fmul_005fn)
1425 #[link_name = "__gmpn_mul_n"]
mpn_mul_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1426 pub fn mpn_mul_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1427 /// See: [`mpn_mul`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fmul)
1428 #[link_name = "__gmpn_mul"]
mpn_mul(rp: mp_ptr, s1p: mp_srcptr, s1n: size_t, s2p: mp_srcptr, s2n: size_t) -> limb_t1429 pub fn mpn_mul(rp: mp_ptr, s1p: mp_srcptr, s1n: size_t, s2p: mp_srcptr, s2n: size_t) -> limb_t;
1430 /// See: [`mpn_sqr`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsqr)
1431 #[link_name = "__gmpn_sqr"]
mpn_sqr(rp: mp_ptr, s1p: mp_srcptr, n: size_t)1432 pub fn mpn_sqr(rp: mp_ptr, s1p: mp_srcptr, n: size_t);
1433 /// See: [`mpn_mul_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fmul_005f1)
1434 #[link_name = "__gmpn_mul_1"]
mpn_mul_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t1435 pub fn mpn_mul_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t;
1436 /// See: [`mpn_addmul_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005faddmul_005f1)
1437 #[link_name = "__gmpn_addmul_1"]
mpn_addmul_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t1438 pub fn mpn_addmul_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t;
1439 /// See: [`mpn_submul_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsubmul_005f1)
1440 #[link_name = "__gmpn_submul_1"]
mpn_submul_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t1441 pub fn mpn_submul_1(rp: mp_ptr, s1p: mp_srcptr, n: size_t, s2limb: limb_t) -> limb_t;
1442 /// See: [`mpn_tdiv_qr`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005ftdiv_005fqr)
1443 #[link_name = "__gmpn_tdiv_qr"]
mpn_tdiv_qr( qp: mp_ptr, rp: mp_ptr, qxn: size_t, np: mp_srcptr, nn: size_t, dp: mp_srcptr, dn: size_t, )1444 pub fn mpn_tdiv_qr(
1445 qp: mp_ptr,
1446 rp: mp_ptr,
1447 qxn: size_t,
1448 np: mp_srcptr,
1449 nn: size_t,
1450 dp: mp_srcptr,
1451 dn: size_t,
1452 );
1453 /// See: [`mpn_divrem_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fdivrem_005f1)
1454 #[link_name = "__gmpn_divrem_1"]
mpn_divrem_1( r1p: mp_ptr, qxn: size_t, s2p: mp_srcptr, s2n: size_t, s3limb: limb_t, ) -> limb_t1455 pub fn mpn_divrem_1(
1456 r1p: mp_ptr,
1457 qxn: size_t,
1458 s2p: mp_srcptr,
1459 s2n: size_t,
1460 s3limb: limb_t,
1461 ) -> limb_t;
1462 }
1463 /// See: [`mpn_divmod_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fdivmod_005f1)
1464 #[inline]
mpn_divmod_1( r1p: mp_ptr, s2p: mp_srcptr, s2n: size_t, s3limb: limb_t, ) -> limb_t1465 pub unsafe extern "C" fn mpn_divmod_1(
1466 r1p: mp_ptr,
1467 s2p: mp_srcptr,
1468 s2n: size_t,
1469 s3limb: limb_t,
1470 ) -> limb_t {
1471 unsafe { mpn_divrem_1(r1p, 0, s2p, s2n, s3limb) }
1472 }
1473 extern "C" {
1474 /// See: [`mpn_divexact_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fdivexact_005f1)
1475 #[link_name = "__gmpn_divexact_1"]
mpn_divexact_1(rp: mp_ptr, sp: mp_srcptr, n: size_t, d: limb_t)1476 pub fn mpn_divexact_1(rp: mp_ptr, sp: mp_srcptr, n: size_t, d: limb_t);
1477 }
1478 /// See: [`mpn_divexact_by3`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fdivexact_005fby3)
1479 #[inline]
mpn_divexact_by3(rp: mp_ptr, sp: mp_srcptr, n: size_t) -> limb_t1480 pub unsafe extern "C" fn mpn_divexact_by3(rp: mp_ptr, sp: mp_srcptr, n: size_t) -> limb_t {
1481 unsafe { mpn_divexact_by3c(rp, sp, n, 0) }
1482 }
1483 extern "C" {
1484 /// See: [`mpn_divexact_by3c`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fdivexact_005fby3c)
1485 #[link_name = "__gmpn_divexact_by3c"]
mpn_divexact_by3c(rp: mp_ptr, sp: mp_srcptr, n: size_t, carry: limb_t) -> limb_t1486 pub fn mpn_divexact_by3c(rp: mp_ptr, sp: mp_srcptr, n: size_t, carry: limb_t) -> limb_t;
1487 /// See: [`mpn_divmod_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fdivmod_005f1)
1488 #[link_name = "__gmpn_mod_1"]
mpn_mod_1(s1p: mp_srcptr, s1n: size_t, s2limb: limb_t) -> limb_t1489 pub fn mpn_mod_1(s1p: mp_srcptr, s1n: size_t, s2limb: limb_t) -> limb_t;
1490 /// See: [`mpn_lshift`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005flshift)
1491 #[link_name = "__gmpn_lshift"]
mpn_lshift(rp: mp_ptr, sp: mp_srcptr, n: size_t, count: c_uint) -> limb_t1492 pub fn mpn_lshift(rp: mp_ptr, sp: mp_srcptr, n: size_t, count: c_uint) -> limb_t;
1493 /// See: [`mpn_rshift`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005frshift)
1494 #[link_name = "__gmpn_rshift"]
mpn_rshift(rp: mp_ptr, sp: mp_srcptr, n: size_t, count: c_uint) -> limb_t1495 pub fn mpn_rshift(rp: mp_ptr, sp: mp_srcptr, n: size_t, count: c_uint) -> limb_t;
1496 /// See: [`mpn_cmp`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcmp)
1497 #[link_name = "__gmpn_cmp"]
mpn_cmp(s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> c_int1498 pub fn mpn_cmp(s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> c_int;
1499 /// See: [`mpn_zero_p`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fzero_005fp)
1500 #[link_name = "__gmpn_zero_p"]
mpn_zero_p(sp: mp_srcptr, n: size_t) -> c_int1501 pub fn mpn_zero_p(sp: mp_srcptr, n: size_t) -> c_int;
1502 /// See: [`mpn_gcd`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fgcd)
1503 #[link_name = "__gmpn_gcd"]
mpn_gcd(rp: mp_ptr, xp: mp_ptr, xn: size_t, yp: mp_ptr, yn: size_t) -> size_t1504 pub fn mpn_gcd(rp: mp_ptr, xp: mp_ptr, xn: size_t, yp: mp_ptr, yn: size_t) -> size_t;
1505 /// See: [`mpn_gcd_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fgcd_005f1)
1506 #[link_name = "__gmpn_gcd_1"]
mpn_gcd_1(xp: mp_srcptr, xn: size_t, yimb: limb_t) -> limb_t1507 pub fn mpn_gcd_1(xp: mp_srcptr, xn: size_t, yimb: limb_t) -> limb_t;
1508 /// See: [`mpn_gcdext`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fgcdext)
1509 #[link_name = "__gmpn_gcdext"]
mpn_gcdext( gp: mp_ptr, sp: mp_ptr, sn: *mut size_t, up: mp_ptr, un: size_t, vp: mp_ptr, vn: size_t, ) -> size_t1510 pub fn mpn_gcdext(
1511 gp: mp_ptr,
1512 sp: mp_ptr,
1513 sn: *mut size_t,
1514 up: mp_ptr,
1515 un: size_t,
1516 vp: mp_ptr,
1517 vn: size_t,
1518 ) -> size_t;
1519 /// See: [`mpn_sqrtrem`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsqrtrem)
1520 #[link_name = "__gmpn_sqrtrem"]
mpn_sqrtrem(r1p: mp_ptr, r2p: mp_ptr, sp: mp_srcptr, n: size_t) -> size_t1521 pub fn mpn_sqrtrem(r1p: mp_ptr, r2p: mp_ptr, sp: mp_srcptr, n: size_t) -> size_t;
1522 /// See: [`mpn_sizeinbase`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsizeinbase)
1523 #[link_name = "__gmpn_sizeinbase"]
mpn_sizeinbase(xp: mp_srcptr, n: size_t, base: c_int) -> usize1524 pub fn mpn_sizeinbase(xp: mp_srcptr, n: size_t, base: c_int) -> usize;
1525 /// See: [`mpn_get_str`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fget_005fstr)
1526 #[link_name = "__gmpn_get_str"]
mpn_get_str(str: *mut c_uchar, base: c_int, s1p: mp_ptr, s1n: size_t) -> usize1527 pub fn mpn_get_str(str: *mut c_uchar, base: c_int, s1p: mp_ptr, s1n: size_t) -> usize;
1528 /// See: [`mpn_set_str`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fset_005fstr)
1529 #[link_name = "__gmpn_set_str"]
mpn_set_str(rp: mp_ptr, str: *const c_uchar, strsize: usize, base: c_int) -> size_t1530 pub fn mpn_set_str(rp: mp_ptr, str: *const c_uchar, strsize: usize, base: c_int) -> size_t;
1531 /// See: [`mpn_scan0`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fscan0)
1532 #[link_name = "__gmpn_scan0"]
mpn_scan0(s1p: mp_srcptr, bit: bitcnt_t) -> bitcnt_t1533 pub fn mpn_scan0(s1p: mp_srcptr, bit: bitcnt_t) -> bitcnt_t;
1534 /// See: [`mpn_scan1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fscan1)
1535 #[link_name = "__gmpn_scan1"]
mpn_scan1(s1p: mp_srcptr, bit: bitcnt_t) -> bitcnt_t1536 pub fn mpn_scan1(s1p: mp_srcptr, bit: bitcnt_t) -> bitcnt_t;
1537 /// See: [`mpn_random`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005frandom)
1538 #[link_name = "__gmpn_random"]
mpn_random(r1p: mp_ptr, r1n: size_t)1539 pub fn mpn_random(r1p: mp_ptr, r1n: size_t);
1540 /// See: [`mpn_random2`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005frandom2)
1541 #[link_name = "__gmpn_random2"]
mpn_random2(r1p: mp_ptr, r1n: size_t)1542 pub fn mpn_random2(r1p: mp_ptr, r1n: size_t);
1543 /// See: [`mpn_popcount`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fpopcount)
1544 #[link_name = "__gmpn_popcount"]
mpn_popcount(s1p: mp_srcptr, n: size_t) -> bitcnt_t1545 pub fn mpn_popcount(s1p: mp_srcptr, n: size_t) -> bitcnt_t;
1546 /// See: [`mpn_hamdist`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fhamdist)
1547 #[link_name = "__gmpn_hamdist"]
mpn_hamdist(s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> bitcnt_t1548 pub fn mpn_hamdist(s1p: mp_srcptr, s2p: mp_srcptr, n: size_t) -> bitcnt_t;
1549 /// See: [`mpn_perfect_square_p`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fperfect_005fsquare_005fp)
1550 #[link_name = "__gmpn_perfect_square_p"]
mpn_perfect_square_p(s1p: mp_srcptr, n: size_t) -> c_int1551 pub fn mpn_perfect_square_p(s1p: mp_srcptr, n: size_t) -> c_int;
1552 /// See: [`mpn_and_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fand_005fn)
1553 #[link_name = "__gmpn_and_n"]
mpn_and_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1554 pub fn mpn_and_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1555 /// See: [`mpn_ior_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fior_005fn)
1556 #[link_name = "__gmpn_ior_n"]
mpn_ior_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1557 pub fn mpn_ior_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1558 /// See: [`mpn_xor_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fxor_005fn)
1559 #[link_name = "__gmpn_xor_n"]
mpn_xor_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1560 pub fn mpn_xor_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1561 /// See: [`mpn_andn_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fandn_005fn)
1562 #[link_name = "__gmpn_andn_n"]
mpn_andn_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1563 pub fn mpn_andn_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1564 /// See: [`mpn_iorn_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fiorn_005fn)
1565 #[link_name = "__gmpn_iorn_n"]
mpn_iorn_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1566 pub fn mpn_iorn_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1567 /// See: [`mpn_nand_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fnand_005fn)
1568 #[link_name = "__gmpn_nand_n"]
mpn_nand_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1569 pub fn mpn_nand_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1570 /// See: [`mpn_nior_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fnior_005fn)
1571 #[link_name = "__gmpn_nior_n"]
mpn_nior_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1572 pub fn mpn_nior_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1573 /// See: [`mpn_xnor_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fxnor_005fn)
1574 #[link_name = "__gmpn_xnor_n"]
mpn_xnor_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t)1575 pub fn mpn_xnor_n(rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t);
1576 /// See: [`mpn_com`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcom)
1577 #[link_name = "__gmpn_com"]
mpn_com(rp: mp_ptr, sp: mp_srcptr, n: size_t)1578 pub fn mpn_com(rp: mp_ptr, sp: mp_srcptr, n: size_t);
1579 /// See: [`mpn_copyi`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcopyi)
1580 #[link_name = "__gmpn_copyi"]
mpn_copyi(rp: mp_ptr, s1p: mp_srcptr, n: size_t)1581 pub fn mpn_copyi(rp: mp_ptr, s1p: mp_srcptr, n: size_t);
1582 /// See: [`mpn_copyd`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcopyd)
1583 #[link_name = "__gmpn_copyd"]
mpn_copyd(rp: mp_ptr, s1p: mp_srcptr, n: size_t)1584 pub fn mpn_copyd(rp: mp_ptr, s1p: mp_srcptr, n: size_t);
1585 /// See: [`mpn_zero`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fzero)
1586 #[link_name = "__gmpn_zero"]
mpn_zero(rp: mp_ptr, n: size_t)1587 pub fn mpn_zero(rp: mp_ptr, n: size_t);
1588
1589 // Low-level functions for cryptography
1590
1591 /// See: [`mpn_cnd_add_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcnd_005fadd_005fn)
1592 #[link_name = "__gmpn_cnd_add_n"]
mpn_cnd_add_n( cnd: limb_t, rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t, ) -> limb_t1593 pub fn mpn_cnd_add_n(
1594 cnd: limb_t,
1595 rp: mp_ptr,
1596 s1p: mp_srcptr,
1597 s2p: mp_srcptr,
1598 n: size_t,
1599 ) -> limb_t;
1600 /// See: [`mpn_cnd_sub_n`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcnd_005fsub_005fn)
1601 #[link_name = "__gmpn_cnd_sub_n"]
mpn_cnd_sub_n( cnd: limb_t, rp: mp_ptr, s1p: mp_srcptr, s2p: mp_srcptr, n: size_t, ) -> limb_t1602 pub fn mpn_cnd_sub_n(
1603 cnd: limb_t,
1604 rp: mp_ptr,
1605 s1p: mp_srcptr,
1606 s2p: mp_srcptr,
1607 n: size_t,
1608 ) -> limb_t;
1609 /// See: [`mpn_sec_add_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fadd_005f1)
1610 #[link_name = "__gmpn_sec_add_1"]
mpn_sec_add_1(rp: mp_ptr, ap: mp_srcptr, n: size_t, b: limb_t, tp: mp_ptr) -> limb_t1611 pub fn mpn_sec_add_1(rp: mp_ptr, ap: mp_srcptr, n: size_t, b: limb_t, tp: mp_ptr) -> limb_t;
1612 /// See: [`mpn_sec_add_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fadd_005f1)
1613 #[link_name = "__gmpn_sec_add_1_itch"]
mpn_sec_add_1_itch(n: size_t) -> size_t1614 pub fn mpn_sec_add_1_itch(n: size_t) -> size_t;
1615 /// See: [`mpn_sec_sub_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fsub_005f1)
1616 #[link_name = "__gmpn_sec_sub_1"]
mpn_sec_sub_1(rp: mp_ptr, ap: mp_srcptr, n: size_t, b: limb_t, tp: mp_ptr) -> limb_t1617 pub fn mpn_sec_sub_1(rp: mp_ptr, ap: mp_srcptr, n: size_t, b: limb_t, tp: mp_ptr) -> limb_t;
1618 /// See: [`mpn_sec_sub_1`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fsub_005f1)
1619 #[link_name = "__gmpn_sec_sub_1_itch"]
mpn_sec_sub_1_itch(n: size_t) -> size_t1620 pub fn mpn_sec_sub_1_itch(n: size_t) -> size_t;
1621 /// See: [`mpn_cnd_swap`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fcnd_005fswap)
1622 #[link_name = "__gmpn_cnd_swap"]
mpn_cnd_swap(cnd: limb_t, ap: *mut limb_t, bp: *mut limb_t, n: size_t)1623 pub fn mpn_cnd_swap(cnd: limb_t, ap: *mut limb_t, bp: *mut limb_t, n: size_t);
1624 /// See: [`mpn_sec_mul`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fmul)
1625 #[link_name = "__gmpn_sec_mul"]
mpn_sec_mul( rp: mp_ptr, ap: mp_srcptr, an: size_t, bp: mp_srcptr, bn: size_t, tp: mp_ptr, )1626 pub fn mpn_sec_mul(
1627 rp: mp_ptr,
1628 ap: mp_srcptr,
1629 an: size_t,
1630 bp: mp_srcptr,
1631 bn: size_t,
1632 tp: mp_ptr,
1633 );
1634 /// See: [`mpn_sec_mul_itch`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fmul_005fitch)
1635 #[link_name = "__gmpn_sec_mul_itch"]
mpn_sec_mul_itch(an: size_t, bn: size_t) -> size_t1636 pub fn mpn_sec_mul_itch(an: size_t, bn: size_t) -> size_t;
1637 /// See: [`mpn_sec_sqr`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fsqr)
1638 #[link_name = "__gmpn_sec_sqr"]
mpn_sec_sqr(rp: mp_ptr, ap: mp_srcptr, an: size_t, tp: mp_ptr)1639 pub fn mpn_sec_sqr(rp: mp_ptr, ap: mp_srcptr, an: size_t, tp: mp_ptr);
1640 /// See: [`mpn_sec_sqr_itch`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fsqr_005fitch)
1641 #[link_name = "__gmpn_sec_sqr_itch"]
mpn_sec_sqr_itch(an: size_t) -> size_t1642 pub fn mpn_sec_sqr_itch(an: size_t) -> size_t;
1643 /// See: [`mpn_sec_powm`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fpowm)
1644 #[link_name = "__gmpn_sec_powm"]
mpn_sec_powm( rp: mp_ptr, bp: mp_srcptr, bn: size_t, ep: mp_srcptr, enb: bitcnt_t, mp: mp_srcptr, n: size_t, tp: mp_ptr, )1645 pub fn mpn_sec_powm(
1646 rp: mp_ptr,
1647 bp: mp_srcptr,
1648 bn: size_t,
1649 ep: mp_srcptr,
1650 enb: bitcnt_t,
1651 mp: mp_srcptr,
1652 n: size_t,
1653 tp: mp_ptr,
1654 );
1655 /// See: [`mpn_sec_powm_itch`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fpowm_005fitch)
1656 #[link_name = "__gmpn_sec_powm_itch"]
mpn_sec_powm_itch(bn: size_t, enb: bitcnt_t, n: size_t) -> size_t1657 pub fn mpn_sec_powm_itch(bn: size_t, enb: bitcnt_t, n: size_t) -> size_t;
1658 /// See: [`mpn_sec_tabselect`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005ftabselect)
1659 #[link_name = "__gmpn_sec_tabselect"]
mpn_sec_tabselect( rp: *mut limb_t, tab: *const limb_t, n: size_t, nents: size_t, which: size_t, )1660 pub fn mpn_sec_tabselect(
1661 rp: *mut limb_t,
1662 tab: *const limb_t,
1663 n: size_t,
1664 nents: size_t,
1665 which: size_t,
1666 );
1667 /// See: [`mpn_sec_div_qr`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fdiv_005fqr)
1668 #[link_name = "__gmpn_sec_div_qr"]
mpn_sec_div_qr( qp: mp_ptr, np: mp_ptr, nn: size_t, dp: mp_srcptr, dn: size_t, tp: mp_ptr, ) -> limb_t1669 pub fn mpn_sec_div_qr(
1670 qp: mp_ptr,
1671 np: mp_ptr,
1672 nn: size_t,
1673 dp: mp_srcptr,
1674 dn: size_t,
1675 tp: mp_ptr,
1676 ) -> limb_t;
1677 /// See: [`mpn_sec_div_qr_itch`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fdiv_005fqr_005fitch)
1678 #[link_name = "__gmpn_sec_div_qr_itch"]
mpn_sec_div_qr_itch(nn: size_t, dn: size_t) -> size_t1679 pub fn mpn_sec_div_qr_itch(nn: size_t, dn: size_t) -> size_t;
1680 /// See: [`mpn_sec_div_r`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fdiv_005fr)
1681 #[link_name = "__gmpn_sec_div_r"]
mpn_sec_div_r(np: mp_ptr, nn: size_t, dp: mp_srcptr, dn: size_t, tp: mp_ptr)1682 pub fn mpn_sec_div_r(np: mp_ptr, nn: size_t, dp: mp_srcptr, dn: size_t, tp: mp_ptr);
1683 /// See: [`mpn_sec_div_r_itch`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005fdiv_005fr_005fitch)
1684 #[link_name = "__gmpn_sec_div_r_itch"]
mpn_sec_div_r_itch(nn: size_t, dn: size_t) -> size_t1685 pub fn mpn_sec_div_r_itch(nn: size_t, dn: size_t) -> size_t;
1686 /// See: [`mpn_sec_invert`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005finvert)
1687 #[link_name = "__gmpn_sec_invert"]
mpn_sec_invert( rp: mp_ptr, ap: mp_ptr, mp: mp_srcptr, n: size_t, nbcnt: bitcnt_t, tp: mp_ptr, ) -> c_int1688 pub fn mpn_sec_invert(
1689 rp: mp_ptr,
1690 ap: mp_ptr,
1691 mp: mp_srcptr,
1692 n: size_t,
1693 nbcnt: bitcnt_t,
1694 tp: mp_ptr,
1695 ) -> c_int;
1696 /// See: [`mpn_sec_invert_itch`](../C/GMP/constant.Low_level_Functions.html#index-mpn_005fsec_005finvert_005fitch)
1697 #[link_name = "__gmpn_sec_invert_itch"]
mpn_sec_invert_itch(n: size_t) -> size_t1698 pub fn mpn_sec_invert_itch(n: size_t) -> size_t;
1699 }
1700
1701 // Random Numbers
1702
1703 // Random State Initialization
1704
1705 extern "C" {
1706 /// See: [`gmp_randinit_default`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandinit_005fdefault)
1707 #[link_name = "__gmp_randinit_default"]
randinit_default(state: randstate_ptr)1708 pub fn randinit_default(state: randstate_ptr);
1709 /// See: [`gmp_randinit_mt`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandinit_005fmt)
1710 #[link_name = "__gmp_randinit_mt"]
randinit_mt(state: randstate_ptr)1711 pub fn randinit_mt(state: randstate_ptr);
1712 /// See: [`gmp_randinit_lc_2exp`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandinit_005flc_005f2exp)
1713 #[link_name = "__gmp_randinit_lc_2exp"]
randinit_lc_2exp(state: randstate_ptr, a: mpz_srcptr, c: c_ulong, m2exp: bitcnt_t)1714 pub fn randinit_lc_2exp(state: randstate_ptr, a: mpz_srcptr, c: c_ulong, m2exp: bitcnt_t);
1715 /// See: [`gmp_randinit_lc_2exp_size`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandinit_005flc_005f2exp_005fsize)
1716 #[link_name = "__gmp_randinit_lc_2exp_size"]
randinit_lc_2exp_size(state: randstate_ptr, size: bitcnt_t) -> c_int1717 pub fn randinit_lc_2exp_size(state: randstate_ptr, size: bitcnt_t) -> c_int;
1718 /// See: [`gmp_randinit_set`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandinit_005fset)
1719 #[link_name = "__gmp_randinit_set"]
randinit_set(rop: randstate_ptr, op: randstate_srcptr)1720 pub fn randinit_set(rop: randstate_ptr, op: randstate_srcptr);
1721 /// See: [`gmp_randclear`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandclear)
1722 #[link_name = "__gmp_randclear"]
randclear(state: randstate_ptr)1723 pub fn randclear(state: randstate_ptr);
1724
1725 // Random State Seeding
1726
1727 /// See: [`gmp_randseed`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandseed)
1728 #[link_name = "__gmp_randseed"]
randseed(state: randstate_ptr, seed: mpz_srcptr)1729 pub fn randseed(state: randstate_ptr, seed: mpz_srcptr);
1730 /// See: [`gmp_randseed_ui`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005frandseed_005fui)
1731 #[link_name = "__gmp_randseed_ui"]
randseed_ui(state: randstate_ptr, seed: c_ulong)1732 pub fn randseed_ui(state: randstate_ptr, seed: c_ulong);
1733
1734 // Random State Miscellaneous
1735
1736 /// See: [`gmp_urandomb_ui`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005furandomb_005fui)
1737 #[link_name = "__gmp_urandomb_ui"]
urandomb_ui(state: randstate_ptr, n: c_ulong) -> c_ulong1738 pub fn urandomb_ui(state: randstate_ptr, n: c_ulong) -> c_ulong;
1739 /// See: [`gmp_urandomm_ui`](../C/GMP/constant.Random_Number_Functions.html#index-gmp_005furandomm_005fui)
1740 #[link_name = "__gmp_urandomm_ui"]
urandomm_ui(state: randstate_ptr, n: c_ulong) -> c_ulong1741 pub fn urandomm_ui(state: randstate_ptr, n: c_ulong) -> c_ulong;
1742 }
1743
1744 // Formatted Output
1745
1746 extern "C" {
1747 /// See: [`gmp_printf`](../C/GMP/constant.Formatted_Output.html#index-gmp_005fprintf)
1748 #[link_name = "__gmp_printf"]
printf(fmt: *const c_char, ...) -> c_int1749 pub fn printf(fmt: *const c_char, ...) -> c_int;
1750 /// See: [`gmp_fprintf`](../C/GMP/constant.Formatted_Output.html#index-gmp_005ffprintf)
1751 #[link_name = "__gmp_fprintf"]
fprintf(fp: *mut FILE, fmt: *const c_char, ...) -> c_int1752 pub fn fprintf(fp: *mut FILE, fmt: *const c_char, ...) -> c_int;
1753 /// See: [`gmp_sprintf`](../C/GMP/constant.Formatted_Output.html#index-gmp_005fsprintf)
1754 #[link_name = "__gmp_sprintf"]
sprintf(buf: *mut c_char, fmt: *const c_char, ...) -> c_int1755 pub fn sprintf(buf: *mut c_char, fmt: *const c_char, ...) -> c_int;
1756 /// See: [`gmp_snprintf`](../C/GMP/constant.Formatted_Output.html#index-gmp_005fsnprintf)
1757 #[link_name = "__gmp_snprintf"]
snprintf(buf: *mut c_char, size: usize, fmt: *const c_char, ...) -> c_int1758 pub fn snprintf(buf: *mut c_char, size: usize, fmt: *const c_char, ...) -> c_int;
1759 /// See: [`gmp_asprintf`](../C/GMP/constant.Formatted_Output.html#index-gmp_005fasprintf)
1760 #[link_name = "__gmp_asprintf"]
asprintf(pp: *mut *mut c_char, fmt: *const c_char, ...) -> c_int1761 pub fn asprintf(pp: *mut *mut c_char, fmt: *const c_char, ...) -> c_int;
1762 }
1763
1764 // Formatted Input
1765
1766 extern "C" {
1767 /// See: [`gmp_scanf`](../C/GMP/constant.Formatted_Input.html#index-gmp_005fscanf)
1768 #[link_name = "__gmp_scanf"]
scanf(fmt: *const c_char, ...) -> c_int1769 pub fn scanf(fmt: *const c_char, ...) -> c_int;
1770 /// See: [`gmp_fscanf`](../C/GMP/constant.Formatted_Input.html#index-gmp_005ffscanf)
1771 #[link_name = "__gmp_fscanf"]
fscanf(fp: *mut FILE, fmt: *const c_char, ...) -> c_int1772 pub fn fscanf(fp: *mut FILE, fmt: *const c_char, ...) -> c_int;
1773 /// See: [`gmp_sscanf`](../C/GMP/constant.Formatted_Input.html#index-gmp_005fsscanf)
1774 #[link_name = "__gmp_sscanf"]
sscanf(s: *const c_char, fmt: *const c_char, ...) -> c_int1775 pub fn sscanf(s: *const c_char, fmt: *const c_char, ...) -> c_int;
1776 }
1777
1778 // Custom Allocation
1779
1780 /// See: [`allocate_function`](../C/GMP/constant.Custom_Allocation.html#index-allocate_005ffunction)
1781 ///
1782 /// # Planned change
1783 ///
1784 /// In the next major version of the crate (version 2), this will be
1785 /// changed to
1786 /// `unsafe extern "C" fn(alloc_size: usize) -> *mut c_void`, that is
1787 /// it will no longer be an [`Option`], and the function can also be
1788 /// unsafe.
1789 pub type allocate_function = Option<extern "C" fn(alloc_size: usize) -> *mut c_void>;
1790 /// See: [`reallocate_function`](../C/GMP/constant.Custom_Allocation.html#index-reallocate_005ffunction)
1791 ///
1792 /// # Planned change
1793 ///
1794 /// In the next major version of the crate (version 2), this will be
1795 /// changed to
1796 /// `unsafe extern "C" fn(ptr: *mut c_void, old_size: usize, new_size: usize) -> *mut c_void`,
1797 /// that is it will no longer be an [`Option`].
1798 pub type reallocate_function =
1799 Option<unsafe extern "C" fn(ptr: *mut c_void, old_size: usize, new_size: usize) -> *mut c_void>;
1800 /// See: [`free_function`](../C/GMP/constant.Custom_Allocation.html#index-free_005ffunction)
1801 ///
1802 /// # Planned change
1803 ///
1804 /// In the next major version of the crate (version 2), this will be
1805 /// changed to `unsafe extern "C" fn(ptr: *mut c_void, size: usize)`,
1806 /// that is it will no longer be an [`Option`].
1807 pub type free_function = Option<unsafe extern "C" fn(ptr: *mut c_void, size: usize)>;
1808 extern "C" {
1809 /// See: [`mp_set_memory_functions`](../C/GMP/constant.Custom_Allocation.html#index-mp_005fset_005fmemory_005ffunctions)
1810 ///
1811 /// # Planned change
1812 ///
1813 /// In the next major version of the crate (version 2), the arguments will be of types
1814 /// <code>[Option][`Option`]<[allocate\_function][`allocate_function`]></code>,
1815 /// <code>[Option][`Option`]<[reallocate\_function][`reallocate_function`]></code>
1816 /// and
1817 /// <code>[Option][`Option`]<[free\_function][`free_function`]></code>,
1818 /// since the function types themselves will no longer be [`Option`].
1819 #[link_name = "__gmp_set_memory_functions"]
set_memory_functions( alloc_func_ptr: allocate_function, realloc_func_ptr: reallocate_function, free_func_ptr: free_function, )1820 pub fn set_memory_functions(
1821 alloc_func_ptr: allocate_function,
1822 realloc_func_ptr: reallocate_function,
1823 free_func_ptr: free_function,
1824 );
1825 /// See: [`mp_get_memory_functions`](../C/GMP/constant.Custom_Allocation.html#index-mp_005fget_005fmemory_005ffunctions)
1826 #[link_name = "__gmp_get_memory_functions"]
get_memory_functions( alloc_func_ptr: *mut allocate_function, realloc_func_ptr: *mut reallocate_function, free_func_ptr: *mut free_function, )1827 pub fn get_memory_functions(
1828 alloc_func_ptr: *mut allocate_function,
1829 realloc_func_ptr: *mut reallocate_function,
1830 free_func_ptr: *mut free_function,
1831 );
1832 }
1833
1834 #[cfg(test)]
1835 mod tests {
1836 use crate::gmp;
1837 use core::{mem, ptr::NonNull};
1838
1839 #[test]
check_mpq_num_den_offsets()1840 fn check_mpq_num_den_offsets() {
1841 let mut limbs: [gmp::limb_t; 2] = [1, 1];
1842 let mut q = gmp::mpq_t {
1843 num: gmp::mpz_t {
1844 alloc: 1,
1845 size: 1,
1846 d: NonNull::from(&mut limbs[0]),
1847 },
1848 den: gmp::mpz_t {
1849 alloc: 1,
1850 size: 1,
1851 d: NonNull::from(&mut limbs[1]),
1852 },
1853 };
1854 unsafe {
1855 assert_eq!(&q.num as *const gmp::mpz_t, gmp::mpq_numref_const(&q));
1856 assert_eq!(&q.den as *const gmp::mpz_t, gmp::mpq_denref_const(&q));
1857 assert_eq!(&mut q.num as *mut gmp::mpz_t, gmp::mpq_numref(&mut q));
1858 assert_eq!(&mut q.den as *mut gmp::mpz_t, gmp::mpq_denref(&mut q));
1859 }
1860 }
1861
1862 #[test]
check_limb_size()1863 fn check_limb_size() {
1864 let from_static = unsafe { gmp::bits_per_limb };
1865 let from_type = mem::size_of::<gmp::limb_t>() * 8;
1866 let from_constant = gmp::LIMB_BITS;
1867 assert_eq!(from_static as usize, from_type);
1868 assert_eq!(from_static, from_constant);
1869 }
1870
1871 #[test]
check_version()1872 fn check_version() {
1873 use crate::tests;
1874
1875 let (major, minor, patchlevel) = (6, 2, 1);
1876 let version = "6.2.1";
1877
1878 assert_eq!(gmp::VERSION, major);
1879 assert!(gmp::VERSION_MINOR >= minor);
1880 if cfg!(not(feature = "use-system-libs")) {
1881 assert!(gmp::VERSION_MINOR > minor || gmp::VERSION_PATCHLEVEL >= patchlevel);
1882 if gmp::VERSION_MINOR == minor && gmp::VERSION_PATCHLEVEL == patchlevel {
1883 assert_eq!(unsafe { tests::str_from_cstr(gmp::version) }, version);
1884 }
1885 }
1886 }
1887 }
1888