This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Re: [Caml-list] arbitrarily large integers
• Yann Régis-Gianas
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2002-12-03 (19:16) From: Yann Régis-Gianas Subject: Re: [Caml-list] arbitrarily large integers
```Le Mardi 3 Décembre 2002 08:40, Scott J. a écrit :
> Hi,

Hello,

> is it possible to implement in OCamel arbitrary large integers as
> in Dolphin smalltalk e.g. where e.g. factorial 10000 is evaluated
> very fast

Yes, it's possible : just use the nums library (documented in the
documentation at http://caml.inria.fr/ocaml/htmlman/manual036.html).

An example :

(* directly with Big_int ... *)
open Big_int

let fact n =
let rec fact_ acu p =
if p = zero_big_int then
acu
else
fact_ (mult_big_int acu p) (sub_big_int p unit_big_int)
in
fact_ unit_big_int n;;

string_of_big_int (fact (big_int_of_int 10000));;

(* more convenient with Num. *)

open Num

let n_ = num_of_int

let big_fact n =
let rec fact_ acu p =
if p = n_ 0 then
acu
else
fact_ (acu */ p) (p -/ (n_ 1))
in
fact_ (n_ 1) n;;

string_of_num (big_fact (n_ 10000))

--
Yann Regis-Gianas
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

```