Module Mpq


module Mpq: sig .. end
GMP multiprecision rationals

type t 

GMP multiprecision 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 : t -> unit

Pretty printing


val print : Format.formatter -> t -> unit

Initialization and Assignment Functions



C documentation
val init : unit -> t
val set : t -> t -> unit
val set_z : t -> Mpz.t -> 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 : t -> t
val init_set_z : Mpz.t -> t
val init_set_si : int -> int -> t
val init_set_str : string -> base:int -> t
val init_set_d : float -> t

Conversion Functions



C documentation
val get_d : t -> float
val set_d : t -> float -> unit
val get_z : Mpz.t -> t -> unit
val _get_str : int -> t -> 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 : t -> string
val to_float : t -> float
val of_string : string -> t
val of_float : float -> t
val of_int : int -> t
val of_frac : int -> int -> t
val of_mpz : Mpz.t -> t
val of_mpz2 : Mpz.t -> Mpz.t -> t

Arithmetic Functions



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

Comparison Functions



C documentation
val cmp : t -> t -> int
val cmp_si : t -> int -> int -> int
val sgn : t -> int
val equal : t -> t -> bool

Applying Integer Functions to Rationals



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

Input and Output Functions: not interfaced