From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA21297; Sun, 13 Oct 2002 12:30:00 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA21087 for ; Sun, 13 Oct 2002 12:29:59 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DATx521209; Sun, 13 Oct 2002 12:29:59 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA17141; Sun, 13 Oct 2002 12:29:58 +0200 (MET DST) From: Pierre Weis Message-Id: <200210131029.MAA17141@pauillac.inria.fr> Subject: Re: [Caml-list] Runtime overflow and what to do In-Reply-To: <20021013120456.D7639@verdot.inria.fr> from Daniel de Rauglaudre at "Oct 13, 102 12:04:56 pm" To: daniel.de_rauglaudre@inria.fr (Daniel de Rauglaudre) Date: Sun, 13 Oct 2002 12:29:58 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hi, > > On Sun, Oct 13, 2002 at 11:25:37AM +0200, Xavier Leroy wrote: > > > Multiplication is left as an exercise for the readers :-) > > Much more complicated... I tried that a long time ago when I was > writting a PostScript interpreter, but I found no solution. (* [lenght_of_int] is the maximum number of bits in an integer. *) let length_of_int = Sys.word_size - 2;; let ( * ) n m = if num_bits_int n + num_bits_int m < length_of_int then n * m else raise (Overflow ("*", string_of_int n, string_of_int m)) (* [num_bits_int n] returns the number of significant bits of an integer. *) Just to let people play with the writting of the module :), num_bits_int is left as an exercise to the interested readers (3 lines of Caml code using trivial bit shuffling). Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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