2003-10-24 02:18:01 -07:00
|
|
|
The "libnum" library implements exact-precision arithmetic on
|
|
|
|
big integers and on rationals.
|
1995-11-06 02:34:19 -08:00
|
|
|
|
|
|
|
This library is derived from Valerie Menissie-Morain's implementation
|
2003-10-24 02:18:01 -07:00
|
|
|
of rational arithmetic for Caml V3.1 (INRIA). Xavier Leroy (INRIA)
|
|
|
|
did the Caml Light port. Victor Manuel Gulias Fernandez did the
|
|
|
|
initial Caml Special Light port. Pierre Weis did most of the
|
|
|
|
maintenance and bug fixing.
|
|
|
|
|
|
|
|
Initially, the low-level big integer operations were provided by the
|
|
|
|
BigNum package developed by Bernard Serpette, Jean Vuillemin and
|
2010-01-22 04:48:24 -08:00
|
|
|
Jean-Claude Herve (INRIA and Digital PRL). License issues forced us to
|
2003-10-24 02:18:01 -07:00
|
|
|
replace the BigNum package. The current implementation of low-level
|
|
|
|
big integer operations is due to Xavier Leroy.
|
1995-11-06 02:34:19 -08:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
This library is documented in "The CAML Numbers Reference Manual" by
|
1995-11-06 02:34:19 -08:00
|
|
|
Valerie Menissier-Morain, technical report 141, INRIA, july 1992,
|
2003-10-26 01:35:41 -08:00
|
|
|
available at ftp://ftp.inria.fr/INRIA/publication/RT/RT-0141.ps.gz
|
2003-10-24 02:18:01 -07:00
|
|
|
|
1995-11-06 02:34:19 -08:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
|
|
|
|
To use the bignum library from your programs, just do
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
ocamlc <options> nums.cma <.cmo and .ml files>
|
|
|
|
or
|
|
|
|
ocamlopt <options> nums.cmxa <.cmx and .ml files>
|
1995-11-06 02:34:19 -08:00
|
|
|
|
|
|
|
for the linking phase.
|
|
|
|
|
|
|
|
If you'd like to have the bignum functions available at toplevel, do
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
ocamlmktop -o ocamltopnum <options> nums.cma <.cmo and .ml files>
|
1997-10-14 06:16:44 -07:00
|
|
|
./ocamltopnum
|
1995-11-06 02:34:19 -08:00
|
|
|
|
|
|
|
As an example, try:
|
|
|
|
|
|
|
|
open Num;;
|
|
|
|
let rec fact n =
|
|
|
|
if n = 0 then Int 1 else mult_num (num_of_int n) (fact(n-1));;
|
|
|
|
string_of_num(fact 1000);;
|
|
|
|
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
PROCESSOR-SPECIFIC OPTIMIZATIONS:
|
1995-11-06 02:34:19 -08:00
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
When compiled with GCC, the low-level primitives use "inline extended asm"
|
2010-01-22 04:48:24 -08:00
|
|
|
to exploit useful features of the target processor (additions and
|
2003-10-24 02:18:01 -07:00
|
|
|
subtractions with carry; double-width multiplication, division).
|
|
|
|
Here are the processors for which such optimizations are available:
|
2003-10-26 01:35:41 -08:00
|
|
|
IA32 (x86) (carry, dwmult, dwdiv, 64-bit ops with SSE2 if available)
|
|
|
|
AMD64 (Opteron) (carry, dwmult, dwdiv)
|
|
|
|
PowerPC (carry, dwmult)
|
|
|
|
Alpha (dwmult)
|
|
|
|
SPARC (carry, dwmult, dwdiv)
|
|
|
|
MIPS (dwmult)
|