README
1The "libnum" library implements exact-precision arithmetic on
2big integers and on rationals.
3
4This library is derived from Valerie Menissie-Morain's implementation
5of rational arithmetic for Caml V3.1 (INRIA). Xavier Leroy (INRIA)
6did the Caml Light port. Victor Manuel Gulias Fernandez did the
7initial Caml Special Light port. Pierre Weis did most of the
8maintenance and bug fixing.
9
10Initially, the low-level big integer operations were provided by the
11BigNum package developed by Bernard Serpette, Jean Vuillemin and
12Jean-Claude Herve (INRIA and Digital PRL). License issues forced us to
13replace the BigNum package. The current implementation of low-level
14big integer operations is due to Xavier Leroy.
15
16This library is documented in "The CAML Numbers Reference Manual" by
17Valerie Menissier-Morain, technical report 141, INRIA, july 1992,
18available at ftp://ftp.inria.fr/INRIA/publication/RT/RT-0141.ps.gz
19
20
21USAGE:
22
23To use the bignum library from your programs, just do
24
25 ocamlc <options> nums.cma <.cmo and .ml files>
26or
27 ocamlopt <options> nums.cmxa <.cmx and .ml files>
28
29for the linking phase.
30
31If you'd like to have the bignum functions available at toplevel, do
32
33 ocamlmktop -o ocamltopnum <options> nums.cma <.cmo and .ml files>
34 ./ocamltopnum
35
36As an example, try:
37
38 open Num;;
39 let rec fact n =
40 if n = 0 then Int 1 else mult_num (num_of_int n) (fact(n-1));;
41 string_of_num(fact 1000);;
42
43
44PROCESSOR-SPECIFIC OPTIMIZATIONS:
45
46When compiled with GCC, the low-level primitives use "inline extended asm"
47to exploit useful features of the target processor (additions and
48subtractions with carry; double-width multiplication, division).
49Here are the processors for which such optimizations are available:
50 IA32 (x86) (carry, dwmult, dwdiv, 64-bit ops with SSE2 if available)
51 AMD64 (Opteron) (carry, dwmult, dwdiv)
52 PowerPC (carry, dwmult)
53 Alpha (dwmult)
54 SPARC (carry, dwmult, dwdiv)
55 MIPS (dwmult)
56