GMP: Multi-precision Arithmetic
This library provides safe low-level bindings to GMP, the GNU Multi-Precision Arithmetic library. This manual assumes familiarity with the relevant parts of the GMP manual.
(require gmp) | package: gmp-lib |
This package is distributed under the LGPL. Note that the GMP native library is dual-licensed under the LGPLv3 and the GPLv2 (see copying conditions for details).
1 mpz: Multi-precision Integers
An mpz (mpz_t) is a mutable value containing an arbitrary-precision integer. In this library, such values are created with mpz and recognized with mpz?. Their backing storage is automatically initialized and garbage-collected.
procedure
n : (or/c exact-integer? mpz?) = 0
procedure
z : mpz? n : exact-integer?
procedure
(mpz->number z) → exact-integer?
z : mpz?
procedure
z : mpz?
procedure
(mpz-positive? z) → boolean?
z : mpz?
procedure
(mpz-negative? z) → boolean?
z : mpz?
procedure
(mpz->bytes z size signed? [ big-endian? dest-buf] dest-start) → bytes? z : mpz? size : (or/c exact-positive-integer? #f) signed? : boolean? big-endian? : boolean? = #t dest-buf : bytes? = (make-bytes size) dest-start : 0
procedure
(bytes->mpz buf signed? [big-endian? start end]) → mpz?
buf : bytes? signed? : boolean? big-endian? : boolean? = #t start : exact-nonnegative-integer? = 0 end : exact-nonnegative-integer? = (bytes-length buf)
procedure
(mpz-bytes-length z signed?) → exact-positive-integer?
z : mpz? signed? : boolean?
1.1 Operations on mpz Values
The following operations are supported. By GMP convention, destination arguments come first, followed by source operands.
procedure
rop : mpz? op : mpz?
procedure
(mpz_set_ui rop op) → void?
rop : mpz? op : unsigned-long
procedure
(mpz_set_si rop op) → void?
rop : mpz? op : signed-long
procedure
rop : mpz? op : rational?
procedure
rop : mpz? op : mpq?
procedure
(mpz_set_str rop op) → void?
rop : mpz op : string?
procedure
rop11 : mpz? rop2 : mpz?
procedure
op : mpz?
procedure
(mpz_get_si op) → exact-integer?
op : mpz?
procedure
op : mpz?
procedure
(mpz_get_d_2exp op) →
rational? exact-integer? op : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_add_ui rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_sub_ui rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
(mpz_ui_sub rop op1 op2) → void?
rop : mpz? op1 : unsigned-long op2 : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_mul_si rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : signed-long
procedure
(mpz_mul_ui rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
(mpz_addmul rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_addmul_ui rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
(mpz_submul rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_submul_ui rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
(mpz_mul_2exp rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
rop : mpz? op : mpz?
procedure
rop : mpz? op : mpz?
procedure
(mpz_pow_ui rop base exp) → void?
rop : mpz? base : mpz? exp : unsigned-long
procedure
(mpz_ui_pow_ui rop base exp) → void?
rop : mpz? base : unsigned-long exp : unsigned-long
procedure
root : mpz? u : mpz? n : unsigned-long
procedure
(mpz_rootrem root rem u n) → void?
root : mpz? rem : mpz? u : mpz? n : unsigned-long
procedure
root : mpz? op : mpz?
procedure
(mpz_sqrtrem root rem op) → void?
root : mpz? rem : mpz? op : mpz?
procedure
op : mpz?
procedure
op : mpz?
procedure
(mpz_probab_prime_p n reps) → exact-integer?
n : mpz? reps : signed-integer
procedure
(mpz_nextprime rop op) → void?
rop : mpz? op : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_gcd_ui rop op1 op2) → unsigned-long
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
(mpz_gcdext g s t a b) → void?
g : mpz? s : mpz? t : mpz? a : mpz? b : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_lcm_ui rop op1 op2) → void?
rop : mpz? op1 : mpz? op2 : unsigned-long
procedure
(mpz_invert rop op1 op2) → exact-integer?
rop : mpz? op1 : mpz? op2 : mpz?
procedure
(mpz_kronecker a b) → exact-integer?
a : mpz? b : mpz?
procedure
(mpz_kronecker_si a b) → exact-integer?
a : mpz? b : signed-long
procedure
(mpz_kronecker_ui a b) → exact-integer?
a : mpz? b : unsigned-long
procedure
(mpz_si_kronecker a b) → exact-integer?
a : signed-long b : mpz?
procedure
(mpz_ui_kronecker a b) → exact-integer?
a : unsigned-long b : mpz?
procedure
(mpz_remove rop op f) → exact-nonnegative-integer?
rop : mpz? op : mpz? f : mpz?
procedure
(mpz_fac_ui rop op) → void?
rop : mpz? op : mpz?
procedure
(mpz_primordial_ui rop n) → void?
rop : mpz? n : unsigned-long
procedure
(mpz_bin_ui rop n k) → void?
rop : mpz? n : mpz? k : unsigned-long
procedure
(mpz_bin_uiui rop n k) → void?
rop : mpz? n : unsigned-long k : unsigned-long
procedure
(mpz_fib_ui fn n) → void?
fn : mpz? n : unsigned-long
procedure
(mpz_fib2_ui fn fnsub1 n) → void?
fn : mpz? fnsub1 : mpz? n : unsigned-long
procedure
(mpz_lucnum_ui ln n) → void?
ln : mpz? n : unsigned-long
procedure
(mpz_lucnum2_ui ln lnsub1 n) → void?
ln : mpz? lnsub1 : mpz? n : unsigned-long
procedure
(mpz_cmp op1 op2) → exact-integer?
op1 : mpz? op2 : mpz?
procedure
(mpz_cmp_d op1 op2) → exact-integer?
op1 : mpz? op2 : real?
procedure
(mpz_cmp_si op1 op2) → exact-integer?
op1 : mpz? op2 : signed-long
procedure
(mpz_cmp_ui op1 op2) → exact-integer?
op1 : mpz? op2 : unsigned-long
procedure
(mpz_cmpabs op1 op2) → exact-integer?
op1 : mpz? op2 : mpz?
procedure
(mpz_cmpabs_d op1 op2) → exact-integer?
op1 : mpz? op2 : real?
procedure
(mpz_cmpabs_ui op1 op2) → exact-integer?
op1 : mpz? op2 : unsigned-long
procedure
op : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
rop : mpz? op1 : mpz? op2 : mpz?
procedure
rop : mpz? op : mpz?
procedure
op : mpz?
procedure
(mpz_hamdist op1 op2) → exact-nonnegative-integer?
op1 : mpz? op2 : mpz?
procedure
(mpz_scan0 op start-bit) → exact-nonnegative-integer?
op : mpz? start-bit : exact-nonnegative-integer?
procedure
(mpz_scan1 op start-bit) → exact-nonnegative-integer?
op : mpz? start-bit : exact-nonnegative-integer?
procedure
(mpz_clrbit rop bit-index) → void?
rop : mpz? bit-index : exact-nonnegative-integer?
procedure
(mpz_combit rop bit-index) → void?
rop : mpz? bit-index : exact-nonnegative-integer?
procedure
(mpz_tstbit op bit-index) → (or/c 0 1)
op : mpz? bit-index : exact-nonnegative-integer?
procedure
(mpz_urandomb rop state n) → void?
rop : mpz? state : gmp-randstate? n : exact-nonnegative-integer?
procedure
(mpz_urandomm rop state n) → void?
rop : mpz? state : gmp-randstate? n : mpz?
procedure
(mpz_rrandomb rop state n) → void?
rop : mpz? state : gmp-randstate? n : exact-nonnegative-integer?
Added in version 1.2 of package gmp-lib.
procedure
(mpz_fits_ulong_p op) → exact-integer?
op : mpz?
procedure
(mpz_fits_slong_p op) → exact-integer?
op : mpz?
procedure
(mpz_fits_uint_p op) → exact-integer?
op : mpz?
procedure
(mpz_fits_sint_p op) → exact-integer?
op : mpz?
procedure
(mpz_fits_ushort_p op) → exact-integer?
op : mpz?
procedure
(mpz_fits_sshort_p op) → exact-integer?
op : mpz?
procedure
(mpz_odd_p op) → exact-integer?
op : mpz?
procedure
(mpz_even_p op) → exact-integer?
op : mpz?
procedure
(mpz_sizeinbase op base) → exact-nonnegative-integer?
op : mpz? base : (integer-in 2 62)
procedure
op : mpz?
procedure
(mpz_getlimbn op n) → exact-nonnegative-integer?
op : mpz? n : unsigned-long
2 mpq: Multi-precision Rational Numbers
An mpq (mpq_t) is a mutable value containing a rational number with arbitrary-precision numerator and denominator. In this library, such values are created with mpq and recognized with mpq?. Their backing storage is automatically initialized and garbage-collected.
procedure
(mpq->number q) → (and/c rational? exact?)
q : mpq?
procedure
q : mpq?
procedure
(mpq-positive? q) → boolean?
q : mpq?
procedure
(mpq-negative? q) → boolean?
q : mpq?
2.1 Operations on mpq Values
The following operations are supported. By GMP convention, destination arguments come first, followed by source operands.
procedure
(mpq_canonicalize op) → void?
op : mpq?
procedure
rop : mpq? op : mpq?
procedure
rop : mpq? op : mpz?
procedure
(mpq_set_ui rop n d) → void?
rop : mpq? n : unsigned-long d : unsigned-long
procedure
(mpq_set_si rop n d) → void?
rop : mpq? n : signed-long d : unsigned-long
procedure
rop1 : mpq? rop2 : mpq?
procedure
rop : mpq? op1 : mpq? op2 : mpq?
procedure
rop : mpq? op1 : mpq? op2 : mpq?
procedure
rop : mpq? op1 : mpq? op2 : mpq?
procedure
(mpq_mul_2exp rop op1 op2) → void?
rop : mpq? op1 : mpq? op2 : unsigned-long
procedure
rop : mpq? op1 : mpq? op2 : mpq?
procedure
(mpq_div_2exp rop op1 op2) → void?
rop : mpq? op1 : mpq? op2 : unsigned-long?
procedure
rop : mpq? op : mpq?
procedure
rop : mpq? op : mpq?
procedure
rop : mpq? op : mpq?
procedure
(mpq_cmp op1 op2) → exact-integer?
op1 : mpq? op2 : mpq?
procedure
(mpq_cmp_z op1 op2) → exact-integer?
op1 : mpq? op2 : mpz?
procedure
(mpq_cmp_ui op1 n2 d2) → exact-integer?
op1 : mpq? n2 : unsigned-long d2 : unsigned-long
procedure
(mpq_cmp_si op1 n2 d2) → exact-integer?
op1 : mpq? n2 : signed-long d2 : unsigned-long
procedure
(mpq_equal op1 op2) → exact-integer?
op1 : mpq? op2 : mpq?
procedure
op : mpq?
procedure
(mpq_get_num num rational) → void?
num : mpz? rational : mpq?
procedure
(mpq_get_den den rational) → void?
den : mpz? rational : mpq?
procedure
(mpq_set_num rational num) → void?
rational : mpq? num : mpz?
procedure
(mpq_set_den rational den) → void?
rational : mpq? den : mpq?
3 Random Number Generation
A randstate (gmp_randstate_t) represents a random number generation algorithm and its state. In this library, such values are recognized with gmp-randstate? and created with gmp-randstate and gmp-randstate-mt. They are automatically initialized and garbage-collected.
procedure
(gmp-randstate? v) → boolean?
v : any/c
Added in version 1.2 of package gmp-lib.
procedure
procedure
Added in version 1.2 of package gmp-lib.
procedure
(gmp_randseed state seed) → void?
state : gmp-randstate? seed : mpz?
procedure
(gmp_randseed_ui state seed) → void?
state : gmp-randstate? seed : exact-nonnegative-integer?
Added in version 1.2 of package gmp-lib.
procedure
(gmp_urandomb_ui state n) → exact-nonnegative-integer?
state : gmp-randstate? n : exact-nonnegative-integer?
procedure
(gmp_urandomm_ui state n) → exact-nonnegative-integer?
state : gmp_randstate? n : exact-positive-integer?
Added in version 1.2 of package gmp-lib.