Module Mpz

module Mpz: sig .. end
GMP multi-precision integers

type 'a tt 

GMP multi-precision integers
type m 
Mutable tag
type f 
Functional (immutable) tag
type t = m tt 
Mutable multi-precision integer

The following operations are mapped as much as possible to their C counterpart. In case of imperative functions (like set, add, ...) the first parameter of type t is an out-parameter and holds the result when the function returns. For instance, add x y z adds the values of y and z and stores the result in x.

These functions are as efficient as their C counterpart: they do not imply additional memory allocation, unlike the corresponding functions in the module Mpzf.

Pretty printing


val print : Format.formatter -> 'a tt -> unit

Initialization Functions



C documentation
val init : unit -> 'a tt
val init2 : int -> 'a tt
val realloc2 : t -> int -> unit

Assignement Functions



C documentation

The first parameter holds the result.
val set : t -> 'a tt -> unit
val set_si : t -> int -> unit
val set_d : t -> float -> unit

For set_q: t -> Mpq.t -> unit, see Mpq.get_z
val _set_str : t -> string -> int -> unit
val set_str : t -> string -> base:int -> unit
val swap : t -> t -> unit

Combined Initialization and Assignment Functions



C documentation
val init_set : 'a tt -> 'b tt
val init_set_si : int -> 'a tt
val init_set_d : float -> 'a tt
val _init_set_str : string -> int -> 'a tt
val init_set_str : string -> base:int -> t

Conversion Functions



C documentation
val get_si : 'a tt -> nativeint
val get_int : 'a tt -> int
val get_d : 'a tt -> float
val get_d_2exp : 'a tt -> float * int
val _get_str : int -> 'a tt -> string
val get_str : base:int -> 'a tt -> string

User Conversions



These functions are additions to or renaming of functions offered by the C library.
val to_string : 'a tt -> string
val to_float : 'a tt -> float
val of_string : string -> 'a tt
val of_float : float -> 'a tt
val of_int : int -> 'a tt

Arithmetic Functions



C documentation

The first parameter holds the result.
val add : t -> 'a tt -> 'b tt -> unit
val add_ui : t -> 'a tt -> int -> unit
val sub : t -> 'a tt -> 'b tt -> unit
val sub_ui : t -> 'a tt -> int -> unit
val ui_sub : t -> int -> 'a tt -> unit
val mul : t -> 'a tt -> 'b tt -> unit
val mul_si : t -> 'a tt -> int -> unit
val addmul : t -> 'a tt -> 'b tt -> unit
val addmul_ui : t -> 'a tt -> int -> unit
val submul : t -> 'a tt -> 'b tt -> unit
val submul_ui : t -> 'a tt -> int -> unit
val mul_2exp : t -> 'a tt -> int -> unit
val neg : t -> 'a tt -> unit
val abs : t -> 'a tt -> unit

Division Functions



C documentation

c stands for ceiling, f for floor, and t for truncate (rounds toward 0).

Ceiling division


val cdiv_q : t -> 'a tt -> 'b tt -> unit
The first parameter holds the quotient.
val cdiv_r : t -> 'a tt -> 'b tt -> unit
The first parameter holds the remainder.
val cdiv_qr : t -> t -> 'a tt -> 'b tt -> unit
The two first parameters hold resp. the quotient and the remainder).
val cdiv_q_ui : t -> 'a tt -> int -> int
The first parameter holds the quotient.
val cdiv_r_ui : t -> 'a tt -> int -> int
The first parameter holds the remainder.
val cdiv_qr_ui : t -> t -> 'a tt -> int -> int
The two first parameters hold resp. the quotient and the remainder).
val cdiv_ui : 'a tt -> int -> int
val cdiv_q_2exp : t -> 'a tt -> int -> unit
The first parameter holds the quotient.
val cdiv_r_2exp : t -> 'a tt -> int -> unit
The first parameter holds the remainder.

Floor division


val fdiv_q : t -> 'a tt -> 'b tt -> unit
val fdiv_r : t -> 'a tt -> 'b tt -> unit
val fdiv_qr : t -> t -> 'a tt -> 'b tt -> unit
val fdiv_q_ui : t -> 'a tt -> int -> int
val fdiv_r_ui : t -> 'a tt -> int -> int
val fdiv_qr_ui : t -> t -> 'a tt -> int -> int
val fdiv_ui : 'a tt -> int -> int
val fdiv_q_2exp : t -> 'a tt -> int -> unit
val fdiv_r_2exp : t -> 'a tt -> int -> unit

Truncate division


val tdiv_q : t -> 'a tt -> 'b tt -> unit
val tdiv_r : t -> 'a tt -> 'b tt -> unit
val tdiv_qr : t -> t -> 'a tt -> 'b tt -> unit
val tdiv_q_ui : t -> 'a tt -> int -> int
val tdiv_r_ui : t -> 'a tt -> int -> int
val tdiv_qr_ui : t -> t -> 'a tt -> int -> int
val tdiv_ui : 'a tt -> int -> int
val tdiv_q_2exp : t -> 'a tt -> int -> unit
val tdiv_r_2exp : t -> 'a tt -> int -> unit

Other division-related functions


val gmod : t -> 'a tt -> 'b tt -> unit
val gmod_ui : t -> 'a tt -> int -> int
val divexact : t -> 'a tt -> 'b tt -> unit
val divexact_ui : t -> 'a tt -> int -> unit
val divisible_p : 'a tt -> 'b tt -> bool
val divisible_ui_p : 'a tt -> int -> bool
val divisible_2exp_p : 'a tt -> int -> bool
val congruent_p : 'a tt -> 'b tt -> 'c tt -> bool
val congruent_ui_p : 'a tt -> int -> int -> bool
val congruent_2exp_p : 'a tt -> 'b tt -> int -> bool

Exponentiation Functions



C documentation
val _powm : t -> 'a tt -> 'b tt -> 'c tt -> unit
val _powm_ui : t -> 'a tt -> int -> 'b tt -> unit
val powm : t -> 'a tt -> 'b tt -> modulo:'c tt -> unit
val powm_ui : t -> 'a tt -> int -> modulo:'b tt -> unit
val pow_ui : t -> 'a tt -> int -> unit
val ui_pow_ui : t -> int -> int -> unit

Root Extraction Functions



C documentation
val root : t -> 'a tt -> int -> bool
val sqrt : t -> 'a tt -> unit
val _sqrtrem : t -> t -> 'a tt -> unit
val sqrtrem : t -> remainder:t -> 'a tt -> unit
val perfect_power_p : 'a tt -> bool
val perfect_square_p : 'a tt -> bool

Number Theoretic Functions



C documentation
val probab_prime_p : 'a tt -> int -> int
val nextprime : t -> 'a tt -> unit
val gcd : t -> 'a tt -> 'b tt -> unit
val gcd_ui : t option -> 'a tt -> int -> int
val _gcdext : t -> t -> t -> 'a tt -> 'b tt -> unit
val gcdext : gcd:t -> alpha:t -> beta:t -> 'a tt -> 'b tt -> unit
val lcm : t -> 'a tt -> 'b tt -> unit
val lcm_ui : t -> 'a tt -> int -> unit
val invert : t -> 'a tt -> 'b tt -> bool
val jacobi : 'a tt -> 'b tt -> int
val legendre : 'a tt -> 'b tt -> int
val kronecker : 'a tt -> 'b tt -> int
val kronecker_si : 'a tt -> int -> int
val si_kronecker : int -> 'a tt -> int
val remove : t -> 'a tt -> 'b tt -> int
val fac_ui : t -> int -> unit
val bin_ui : t -> 'a tt -> int -> unit
val bin_uiui : t -> int -> int -> unit
val fib_ui : t -> int -> unit
val fib2_ui : t -> t -> int -> unit
val lucnum_ui : t -> int -> unit
val lucnum2_ui : t -> t -> int -> unit

Comparison Functions



C documentation
val cmp : 'a tt -> 'b tt -> int
val cmp_d : 'a tt -> float -> int
val cmp_si : 'a tt -> int -> int
val cmpabs : 'a tt -> 'b tt -> int
val cmpabs_d : 'a tt -> float -> int
val cmpabs_ui : 'a tt -> int -> int
val sgn : 'a tt -> int

Logical and Bit Manipulation Functions



C documentation
val gand : t -> 'a tt -> 'b tt -> unit
val ior : t -> 'a tt -> 'b tt -> unit
val xor : t -> 'a tt -> 'b tt -> unit
val com : t -> 'a tt -> unit
val popcount : 'a tt -> int
val hamdist : 'a tt -> 'b tt -> int
val scan0 : 'a tt -> int -> int
val scan1 : 'a tt -> int -> int
val setbit : t -> int -> unit
val clrbit : t -> int -> unit
val tstbit : 'a tt -> int -> bool

Input and Output Functions: not interfaced



Random Number Functions: see Gmp_random module



Integer Import and Export Functions



C documentation
val _import : t ->
(int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t ->
int -> int -> unit
val _export : 'a tt ->
int -> int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t
val import : dest:t ->
(int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t ->
order:int -> endian:int -> unit
val export : 'a tt ->
order:int ->
endian:int -> (int, Bigarray.int32_elt, Bigarray.c_layout) Bigarray.Array1.t

Miscellaneous Functions



C documentation
val fits_int_p : 'a tt -> bool
val odd_p : 'a tt -> bool
val even_p : 'a tt -> bool
val size : 'a tt -> int
val sizeinbase : 'a tt -> int -> int
val fits_ulong_p : 'a tt -> bool
val fits_slong_p : 'a tt -> bool
val fits_uint_p : 'a tt -> bool
val fits_sint_p : 'a tt -> bool
val fits_ushort_p : 'a tt -> bool
val fits_sshort_p : 'a tt -> bool