Module Mpq

module Mpq: sig .. end
GMP multi-precision rationals

type 'a tt 

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

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 Mpqf.

val canonicalize : 'a tt -> unit

Pretty printing


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

Initialization and Assignment Functions



C documentation
val init : unit -> 'a tt
val set : t -> 'a tt -> unit
val set_z : t -> 'a Mpz.tt -> unit
val set_si : t -> int -> int -> unit
val _set_str : t -> string -> int -> unit
val set_str : t -> string -> base:int -> unit
val swap : t -> t -> unit

Additional Initialization and Assignements functions



These functions are additions to or renaming of functions offered by the C library.
val init_set : 'a tt -> 'b tt
val init_set_z : 'a Mpz.tt -> 'b tt
val init_set_si : int -> int -> 'a tt
val init_set_str : string -> base:int -> 'a tt
val init_set_d : float -> 'a tt

Conversion Functions



C documentation
val get_d : 'a tt -> float
val set_d : t -> float -> unit
val get_z : Mpz.t -> 'a tt -> unit
val _get_str : int -> 'a tt -> string
val get_str : base:int -> t -> string

User Conversions



These functionss are additions to or renaming of functions offeered 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
val of_frac : int -> int -> 'a tt
val of_mpz : 'a Mpz.tt -> 'b tt
val of_mpz2 : 'a Mpz.tt -> 'b Mpz.tt -> 'c tt

Arithmetic Functions



C documentation
val add : t -> 'a tt -> 'b tt -> unit
val sub : t -> 'a tt -> 'b tt -> unit
val mul : t -> 'a tt -> 'b tt -> unit
val mul_2exp : t -> 'a tt -> int -> unit
val div : t -> 'a tt -> 'b tt -> unit
val div_2exp : t -> 'a tt -> int -> unit
val neg : t -> 'a tt -> unit
val abs : t -> 'a tt -> unit
val inv : t -> 'a tt -> unit

Comparison Functions



C documentation
val cmp : 'a tt -> 'b tt -> int
val cmp_si : 'a tt -> int -> int -> int
val sgn : 'a tt -> int
val equal : 'a tt -> 'b tt -> bool

Applying Integer Functions to Rationals



C documentation
val get_num : Mpz.t -> 'a tt -> unit
val get_den : Mpz.t -> 'a tt -> unit
val set_num : t -> 'a Mpz.tt -> unit
val set_den : t -> 'a Mpz.tt -> unit

Input and Output Functions: not interfaced