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 IAA22257; Fri, 11 Oct 2002 08:42:31 +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 IAA21840 for ; Fri, 11 Oct 2002 08:42:31 +0200 (MET DST) Received: from grisu.bik-gmbh.de (In-Planung---------X.BIK-GmbH.de [212.12.55.66] (may be forged)) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g9B6gU523357 for ; Fri, 11 Oct 2002 08:42:30 +0200 (MET DST) Received: from hars.de (prony.bik-gmbh.de [194.233.237.133]) by grisu.bik-gmbh.de (8.12.3/8.12.3) with ESMTP id g9B6gRU8070554; Fri, 11 Oct 2002 08:42:27 +0200 (CEST) (envelope-from florian@hars.de) Message-ID: <3DA672CD.2020301@hars.de> Date: Fri, 11 Oct 2002 08:42:21 +0200 From: Florian Hars User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.1) Gecko/20020826 X-Accept-Language: de-de, en-us, en MIME-Version: 1.0 To: "Scott J," CC: caml-list@inria.fr Subject: Re: [Caml-list] Runtime overflow and what to do References: <00bd01c2706d$e7cd68e0$0100a8c0@janxp> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Scott J, wrote: > Because an integer number is represented by a fixed number of bytes I > will get a runtime overflow if n is chosen too large. You have to check explicitly: # exception Overflow;; exception Overflow # let fact n = let rec fact_r acc n = if n = 1 then acc else if max_int / acc > (n-1) then fact_r (acc * n) (n - 1) else raise Overflow in fact_r 1 n;; val fact : int -> int = # fact 12;; - : int = 479001600 # fact 13;; Exception: Overflow. Yours, Florian ------------------- 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