# Module Mpz

    module Mpz: sig .. end

    type t

GMP multi-precision integers

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 : Stdlib.Format.formatter -> t -> unit

### Initialization Functions

C documentation

    val init : unit -> t

    val init2 : int -> t

    val realloc2 : t -> int -> unit

### Assignement Functions

C documentation

The first parameter holds the result.

    val set : t -> t -> 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 : t -> t

    val init_set_si : int -> t

    val init_set_d : float -> t

    val _init_set_str : string -> int -> t

    val init_set_str : string -> base:int -> t

### Conversion Functions

C documentation

    val get_si : t -> nativeint

    val get_int : t -> int

    val get_d : t -> float

    val get_d_2exp : t -> float * int

    val _get_str : int -> t -> string

    val get_str : base:int -> t -> string

### User Conversions

These functions are additions to or renaming of functions offered by the C library.

    val to_string : t -> string

    val to_float : t -> float

    val of_string : string -> t

    val of_float : float -> t

    val of_int : int -> t

### Arithmetic Functions

C documentation

The first parameter holds the result.

    val add : t -> t -> t -> unit

    val add_ui : t -> t -> int -> unit

    val sub : t -> t -> t -> unit

    val sub_ui : t -> t -> int -> unit

    val ui_sub : t -> int -> t -> unit

    val mul : t -> t -> t -> unit

    val mul_si : t -> t -> int -> unit

    val addmul : t -> t -> t -> unit

    val addmul_ui : t -> t -> int -> unit

    val submul : t -> t -> t -> unit

    val submul_ui : t -> t -> int -> unit

    val mul_2exp : t -> t -> int -> unit

    val neg : t -> t -> unit

    val abs : t -> t -> 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 -> t -> t -> unit

The first parameter holds the quotient.

    val cdiv_r : t -> t -> t -> unit

The first parameter holds the remainder.

    val cdiv_qr : t -> t -> t -> t -> unit

The two first parameters hold resp. the quotient and the remainder).

    val cdiv_q_ui : t -> t -> int -> int

The first parameter holds the quotient.

    val cdiv_r_ui : t -> t -> int -> int

The first parameter holds the remainder.

    val cdiv_qr_ui : t -> t -> t -> int -> int

The two first parameters hold resp. the quotient and the remainder).

    val cdiv_ui : t -> int -> int

    val cdiv_q_2exp : t -> t -> int -> unit

The first parameter holds the quotient.

    val cdiv_r_2exp : t -> t -> int -> unit

The first parameter holds the remainder.

#### Floor division

    val fdiv_q : t -> t -> t -> unit

    val fdiv_r : t -> t -> t -> unit

    val fdiv_qr : t -> t -> t -> t -> unit

    val fdiv_q_ui : t -> t -> int -> int

    val fdiv_r_ui : t -> t -> int -> int

    val fdiv_qr_ui : t -> t -> t -> int -> int

    val fdiv_ui : t -> int -> int

    val fdiv_q_2exp : t -> t -> int -> unit

    val fdiv_r_2exp : t -> t -> int -> unit

#### Truncate division

    val tdiv_q : t -> t -> t -> unit

    val tdiv_r : t -> t -> t -> unit

    val tdiv_qr : t -> t -> t -> t -> unit

    val tdiv_q_ui : t -> t -> int -> int

    val tdiv_r_ui : t -> t -> int -> int

    val tdiv_qr_ui : t -> t -> t -> int -> int

    val tdiv_ui : t -> int -> int

    val tdiv_q_2exp : t -> t -> int -> unit

    val tdiv_r_2exp : t -> t -> int -> unit

#### Other division-related functions

    val gmod : t -> t -> t -> unit

    val gmod_ui : t -> t -> int -> int

    val divexact : t -> t -> t -> unit

    val divexact_ui : t -> t -> int -> unit

    val divisible_p : t -> t -> bool

    val divisible_ui_p : t -> int -> bool

    val divisible_2exp_p : t -> int -> bool

    val congruent_p : t -> t -> t -> bool

    val congruent_ui_p : t -> int -> int -> bool

    val congruent_2exp_p : t -> t -> int -> bool

### Exponentiation Functions

C documentation

    val _powm : t -> t -> t -> t -> unit

    val _powm_ui : t -> t -> int -> t -> unit

    val powm : t -> t -> t -> modulo:t -> unit

    val powm_ui : t -> t -> int -> modulo:t -> unit

    val pow_ui : t -> t -> int -> unit

    val ui_pow_ui : t -> int -> int -> unit

### Root Extraction Functions

C documentation

    val root : t -> t -> int -> bool

    val sqrt : t -> t -> unit

    val _sqrtrem : t -> t -> t -> unit

    val sqrtrem : t -> remainder:t -> t -> unit

    val perfect_power_p : t -> bool

    val perfect_square_p : t -> bool

### Number Theoretic Functions

C documentation

    val probab_prime_p : t -> int -> int

    val nextprime : t -> t -> unit

    val gcd : t -> t -> t -> unit

    val gcd_ui : t option -> t -> int -> int

    val _gcdext : t -> t -> t -> t -> t -> unit

    val gcdext : gcd:t -> alpha:t -> beta:t -> t -> t -> unit

    val lcm : t -> t -> t -> unit

    val lcm_ui : t -> t -> int -> unit

    val invert : t -> t -> t -> bool

    val jacobi : t -> t -> int

    val legendre : t -> t -> int

    val kronecker : t -> t -> int

    val kronecker_si : t -> int -> int

    val si_kronecker : int -> t -> int

    val remove : t -> t -> t -> int

    val fac_ui : t -> int -> unit

    val bin_ui : t -> t -> 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 : t -> t -> int

    val cmp_d : t -> float -> int

    val cmp_si : t -> int -> int

    val cmpabs : t -> t -> int

    val cmpabs_d : t -> float -> int

    val cmpabs_ui : t -> int -> int

    val sgn : t -> int

### Logical and Bit Manipulation Functions

C documentation

    val gand : t -> t -> t -> unit

    val ior : t -> t -> t -> unit

    val xor : t -> t -> t -> unit

    val com : t -> t -> unit

    val popcount : t -> int

    val hamdist : t -> t -> int

    val scan0 : t -> int -> int

    val scan1 : t -> int -> int

    val setbit : t -> int -> unit

    val clrbit : t -> int -> unit

    val tstbit : t -> 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, Stdlib.Bigarray.int32_elt, Stdlib.Bigarray.c_layout)
           Stdlib.Bigarray.Array1.t -> int -> int -> unit

    val _export : t ->
           int ->
           int ->
           (int, Stdlib.Bigarray.int32_elt, Stdlib.Bigarray.c_layout)
           Stdlib.Bigarray.Array1.t

    val import : dest:t ->
           (int, Stdlib.Bigarray.int32_elt, Stdlib.Bigarray.c_layout)
           Stdlib.Bigarray.Array1.t -> order:int -> endian:int -> unit

    val export : t ->
           order:int ->
           endian:int ->
           (int, Stdlib.Bigarray.int32_elt, Stdlib.Bigarray.c_layout)
           Stdlib.Bigarray.Array1.t

### Miscellaneous Functions

C documentation

    val fits_int_p : t -> bool

    val odd_p : t -> bool

    val even_p : t -> bool

    val size : t -> int

    val sizeinbase : t -> int -> int

    val fits_ulong_p : t -> bool

    val fits_slong_p : t -> bool

    val fits_uint_p : t -> bool

    val fits_sint_p : t -> bool

    val fits_ushort_p : t -> bool

    val fits_sshort_p : t -> bool