caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] arbitrarily large integers
@ 2002-12-03  9:47 Yann Régis-Gianas
  0 siblings, 0 replies; 4+ messages in thread
From: Yann Régis-Gianas @ 2002-12-03  9:47 UTC (permalink / raw)
  To: caml-list

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 :

#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


^ permalink raw reply	[flat|nested] 4+ messages in thread
* [Caml-list] arbitrarily large integers
@ 2002-12-03  7:40 Scott J.
  2002-12-03 13:00 ` Jean-Christophe Filliatre
  2002-12-03 18:23 ` Alain.Frisch
  0 siblings, 2 replies; 4+ messages in thread
From: Scott J. @ 2002-12-03  7:40 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

Hi, is it possible to implement in OCamel arbitrary large integers as in Dolphin smalltalk e.g. where e.g. 
factorial 10000 is evaluatedvery fast.

thanks

Scott

[-- Attachment #2: Type: text/html, Size: 722 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-12-03 19:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-03  9:47 [Caml-list] arbitrarily large integers Yann Régis-Gianas
  -- strict thread matches above, loose matches on Subject: below --
2002-12-03  7:40 Scott J.
2002-12-03 13:00 ` Jean-Christophe Filliatre
2002-12-03 18:23 ` Alain.Frisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).