<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/49eb0490758d864f3ae4ec1db650c0cf"
  from="Yann Régis-Gianas &lt;yann@l...&gt;"
  author="Yann Régis-Gianas"
  date="2002-12-03T19:16:12"
  subject="Re: [Caml-list] arbitrarily large integers"
  prev="2002/12/529c10a693efdb53c3c01a00fdc17b7b"
  next="2002/12/5444b071a7de92cfca3138afd5f8db9a"
  prev-thread="2002/12/ae67efc807f684a48e45227aca93f839"
  next-thread="2002/12/2460a60612b172a3906a98662afed12a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Re: [Caml-list] arbitrarily large integers">
<msg 
  url="2002/12/49eb0490758d864f3ae4ec1db650c0cf"
  from="Yann Régis-Gianas &lt;yann@l...&gt;"
  author="Yann Régis-Gianas"
  date="2002-12-03T19:16:12"
  subject="Re: [Caml-list] arbitrarily large integers">
</msg>
</thread>

<contents>
Le Mardi 3 Décembre 2002 08:40, Scott J. a écrit :
&gt; Hi,

	Hello,

&gt; is it possible to implement in OCamel arbitrary large integers as
&gt; in Dolphin smalltalk e.g. where e.g. factorial 10000 is evaluated
&gt; 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 :

#load "nums.cma";;

(* 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

</contents>

</message>

