From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id AC1BDBC69 for ; Tue, 1 May 2007 04:41:56 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l412fs72027514 for ; Tue, 1 May 2007 04:41:55 +0200 X-IronPort-AV: E=Sophos;i="4.14,472,1170595800"; d="scan'208";a="121673946" Received: from ppp8-148.lns1.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.8.148]) by ipmail01.adl2.internode.on.net with ESMTP; 01 May 2007 12:11:52 +0930 Subject: Re: [Caml-list] Int64 overflow checks From: skaller To: Raj B Cc: caml-list@yquem.inria.fr In-Reply-To: References: Content-Type: text/plain Date: Tue, 01 May 2007 12:41:51 +1000 Message-Id: <1177987311.16926.5.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4636A8F2.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 implicitly:01 'int':01 ocaml's:01 ocaml:01 sourceforge:01 wrote:01 overflows:01 integer:01 integer:01 caml-list:01 int:01 int:01 python:02 python:02 On Mon, 2007-04-30 at 12:24 -0500, Raj B wrote: > Hi > > I am writing an implementation of the Python programming language in > OCaml and ran into an interesting issue. > > Python allows the programmer to implicitly perform arbitrary-sized > integer operations by switching internally between its 'int' and > 'long' types. (which seems to translate to OCaml's int64 and BigInt). > > I found an OCaml library on a mailing list which checks for overflow > in 'normal' 32-bit integer operations. How can I check for overflows > in int64 operations so I can switch to big-int if that happens? you use basic maths. For example on addition, you expect a + b > a a + b > b and one of these will be false if you got overflow (something like that). -- John Skaller Felix, successor to C++: http://felix.sf.net