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 JAA22513; Fri, 7 Nov 2003 09:23:37 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA21699 for ; Fri, 7 Nov 2003 09:23:36 +0100 (MET) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hA78NX121742 for ; Fri, 7 Nov 2003 09:23:34 +0100 (MET) Received: from syd-ts22-2600-229.tpgi.com.au (syd-ts22-2600-229.tpgi.com.au [203.26.30.229]) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id hA78NRZ14429; Fri, 7 Nov 2003 19:23:28 +1100 Subject: Re: [Caml-list] Int overflow in literals From: skaller Reply-To: skaller@ozemail.com.au To: Brian Hurt Cc: caml-list@inria.fr In-Reply-To: References: Content-Type: text/plain Message-Id: <1068189744.6194.44.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 07 Nov 2003 18:22:24 +1100 Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ozemail:01 oleg:01 issac:01 trotts:01 in-:99 'int':01 'int:01 backend:01 semantics:01 semantics:01 int:01 int:01 behaviour:01 nov:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 2003-11-03 at 03:23, Brian Hurt wrote: > On 3 Nov 2003, skaller wrote: > > > On Fri, 2003-10-31 at 08:14, Oleg Trott wrote: > > > On Thursday 30 October 2003 03:05 pm, Issac Trotts wrote: > > > > > > > > Or, better yet, use Big_int: > > > > Felix does that, and i'm very happy with the idea. > > Constant folding is done in "infinite" precision. > > The check for size, if done, would occur in the backend > > code generator .. not the parser. > > > > This is a bad idea. I'd like the constant folding to be done in the word > length that the code will be executed in- this way, there is no difference > between code that is executed at run time and code that is executed at > compile time. > The results will be the same, so its a good idea :-) The Felix types 'int', 'long' etc have the same sizes as the corresponding C types. But the semantics are NOT the same. Bitwise operations are not permitted, and the result is undefined on overflow. The Felix type 'int32' on the other hand is required to be two's complement 32 bit, and allows overflow as in C. Bitwise operations are not allowed. The type 'uint32' allows bitwise operations. The constant folder respects these semantics. Actually only int type is folded .. and if the result would overflow at run time then the behaviour of the program is undefined, and so the well defined result of constant folding is correct, since it is an element of the set 'undefined' of all possible results :-) ------------------- 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