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 TAA29840; Sun, 13 Oct 2002 19:07:04 +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 TAA29779 for ; Sun, 13 Oct 2002 19:07:03 +0200 (MET DST) Received: from postfix2-1.free.fr (postfix2-1.free.fr [213.228.0.9]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9DH72529261 for ; Sun, 13 Oct 2002 19:07:03 +0200 (MET DST) Received: from montchapet (dijon-1-a7-62-147-71-215.dial.proxad.net [62.147.71.215]) by postfix2-1.free.fr (Postfix) with ESMTP id BFDCE14B for ; Sun, 13 Oct 2002 19:07:01 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-1" From: Michel Quercia Reply-To: michel.quercia@prepas.org To: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do Date: Sun, 13 Oct 2002 19:06:36 +0200 User-Agent: KMail/1.4.1 References: <20021013120456.D7639@verdot.inria.fr> <200210131029.MAA17141@pauillac.inria.fr> <20021013181458.A28677@pauillac.inria.fr> In-Reply-To: <20021013181458.A28677@pauillac.inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200210131906.36527.michel.quercia@prepas.org> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Le Dimanche 13 Octobre 2002 18:14, Xavier Leroy a écrit : > > [Overflow checking in integer multiplication] > > 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)) > Hmmph... this definition raises Overflow when computing > min_int * 1, or (min_int / 2) * 2, while these products are actually > representable within a machine integer... What about this one ? let mul a b = if a = 0 then 0 else let x = a*b in let q = x/a and r = x mod a in if (q = b) & (r = 0) then x else raise Overflow -- Michel Quercia 23 rue de Montchapet, 21000 Dijon http://michel.quercia.free.fr (maths) http://pauillac.inria.fr/~quercia (informatique) mailto:michel.quercia@prepas.org ------------------- 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