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 NAA04398; Sun, 15 Jul 2001 13:17:15 +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 NAA04582 for ; Sun, 15 Jul 2001 13:17:14 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6FBHCf02051; Sun, 15 Jul 2001 13:17:12 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA04289; Sun, 15 Jul 2001 13:17:12 +0200 (MET DST) Date: Sun, 15 Jul 2001 13:17:12 +0200 From: Xavier Leroy To: "Krishnaswami, Neel" Cc: "'caml-list@inria.fr'" Subject: Re: [Caml-list] Ints and overflow... Message-ID: <20010715131712.A4478@pauillac.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from neelk@cswcasa.com on Fri, Jul 13, 2001 at 03:25:19PM -0400 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > However, this has led me directly into the zone of integer overflow. > Basically, I don't understand what I can expect to be portable, and > I really don't understand what OCaml does -- what is the tagging > scheme, and how does that affect the overflow results I can expect? As long as you're programming in well-typed Caml, the exact details of the tagging scheme do not matter. You get regular 2-complement modulo arithmetic, just like in Java and most if not all C compilers, with 31 bits of precision, or 63 bits if you're lucky enought to run on a 64-bit processor. > For example: Is the integer tag 0 or 1? It's a 1 in the least significant bit, but again you can't observe this from well-typed Caml. > Does it vary by platform? No, but same comment as above. > Can the results vary by how Caml chooses to optimize adds? Normally, no. If it varied, that would be due to a bug in the tagging optimization scheme of the ocamlopt compiler. > Does Caml promise anything at all about the results of an > overflowing integer add? Yes: it wraps around, i.e. you get the result modulo 2^31 (or 2^63 on a 64-bit platform). Hope this answers your questions. - Xavier Leroy ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr