The num library implements exact-precision rational arithmetic. It is built upon the state-of-the-art BigNum arbitrary-precision integer arithmetic package, and therefore achieves very high performance.
The functions provided in this library are fully documented in The CAML Numbers Reference Manual by Valérie Ménissier-Morain, technical report 141, INRIA, july 1992 (available by anonymous FTP from ftp.inria.fr, directory INRIA/publications/RT, file RT-0141.ps.Z). A summary of the functions is given below.
ocamlc -custom other options nums.cma other files -cclib -lnums ocamlopt other options nums.cmxa other files -cclib -lnumsFor interactive use of the nums library, do:
ocamlmktop -custom -o mytop nums.cma -cclib -lnums ./mytop
ocamlc -custom other options nums.cma other files %CAMLLIB%/libnums.lib ocamlopt other options nums.cmxa other files %CAMLLIB%/libnums.libFor interactive use of the nums library, do:
ocamlmktop -custom -o mytop.exe nums.cma %CAMLLIB%/libnums.lib ./mytop.exe
open Nat open Big_int open Ratio
type num = Int of int | Big_int of big_int | Ratio of ratio
val (+/) : num -> num -> num val add_num : num -> num -> num
val minus_num : num -> num
val (-/) : num -> num -> num val sub_num : num -> num -> num
val (*/) : num -> num -> num val mult_num : num -> num -> num
val square_num : num -> num
val (//) : num -> num -> num val div_num : num -> num -> num
val quo_num : num -> num -> num val mod_num : num -> num -> num
val (**/) : num -> num -> num val power_num : num -> num -> num
val is_integer_num : num -> bool
val integer_num : num -> num val floor_num : num -> num val round_num : num -> num val ceiling_num : num -> num
val sign_num : num -> int
val (=/) : num -> num -> bool val (</) : num -> num -> bool val (>/) : num -> num -> bool val (<=/) : num -> num -> bool val (>=/) : num -> num -> bool val (<>/) : num -> num -> bool val eq_num : num -> num -> bool val lt_num : num -> num -> bool val le_num : num -> num -> bool val gt_num : num -> num -> bool val ge_num : num -> num -> bool
val compare_num : num -> num -> int
val max_num : num -> num -> num val min_num : num -> num -> num
val abs_num : num -> num
val succ_num: num -> num
val pred_num: num -> num
val incr_num: num ref -> unit
val decr_num: num ref -> unit
val string_of_num : num -> string
val approx_num_fix : int -> num -> string val approx_num_exp : int -> num -> string
val num_of_string : string -> num
val int_of_num : num -> int val num_of_int : int -> num val nat_of_num : num -> nat val num_of_nat : nat -> num val num_of_big_int : big_int -> num val big_int_of_num : num -> big_int val ratio_of_num : num -> ratio val num_of_ratio : ratio -> num val float_of_num : num -> float
val arith_status: unit -> unit
val get_error_when_null_denominator : unit -> bool val set_error_when_null_denominator : bool -> unit
val get_normalize_ratio : unit -> bool val set_normalize_ratio : bool -> unit
val get_normalize_ratio_when_printing : unit -> bool val set_normalize_ratio_when_printing : bool -> unit
val get_approx_printing : unit -> bool val set_approx_printing : bool -> unit
val get_floating_precision : unit -> int val set_floating_precision : int -> unit