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 AAA11246; Wed, 16 Jun 2004 00:45:42 +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 AAA13718; Wed, 16 Jun 2004 00:45:40 +0200 (MET DST) Received: from salt.cs.brown.edu (salt-dmz.cs.brown.edu [128.148.32.122]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5FMjdSH005149; Wed, 16 Jun 2004 00:45:39 +0200 Received: from localhost (localhost [127.0.0.1]) by salt.cs.brown.edu (Postfix) with ESMTP id D2F08D86F1; Tue, 15 Jun 2004 18:45:38 -0400 (EDT) Received: from salt.cs.brown.edu ([127.0.0.1]) by localhost (salt [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 27489-02; Tue, 15 Jun 2004 18:45:38 -0400 (EDT) Received: from null.cs.brown.edu (null.cs.brown.edu [128.148.38.190]) by salt.cs.brown.edu (Postfix) with ESMTP id AF3C8D86DF; Tue, 15 Jun 2004 18:45:38 -0400 (EDT) Received: from miette (miette [128.148.38.66]) by null.cs.brown.edu (Postfix) with ESMTP id 921093CAA; Tue, 15 Jun 2004 18:45:38 -0400 (EDT) Received: from er by miette with local (Exim 3.36 #1 (Debian)) id 1BaMgU-0001ir-00; Tue, 15 Jun 2004 18:45:38 -0400 Date: Tue, 15 Jun 2004 18:45:38 -0400 From: Manos Renieris To: Xavier Leroy Cc: John Hughes , caml-list@inria.fr Subject: Re: [Caml-list] More or bignums/ints Message-ID: <20040615224538.GA6135@cs.brown.edu> Reply-To: Manos Renieris Mail-Followup-To: Xavier Leroy , John Hughes , caml-list@inria.fr References: <20040611193818.0A43457251@twix.cs.brown.edu> <20040614175552.A28810@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040614175552.A28810@pauillac.inria.fr> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at cs.brown.edu X-Miltered: at concorde with ID 40CF7C13.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; renieris:01 caml-list:01 bignums:01 tweaking:01 2004:99 bignums:01 101.:99 lxor:01 lxor:01 ints:01 ints:01 ocaml:01 int:01 sml:01 0200,:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I think you also need let ( ~- ) x = if x <> min_int then -x else raise Overflow (~- is unary minus, commonly typed in as "-") You still get -1073741824=1073741824 being true if you type in the exact literals. I think fixing this requires tweaking the parser. -- Manos On Mon, Jun 14, 2004 at 05:55:52PM +0200, Xavier Leroy wrote: > Dear John, > > > 2. Is there a way to tell OCaml that ints really are either > > (a) bignums or > > (b) overflow-protected ints (as in SML/NJ, for instance) > > Solution (b) is much easier, provided you don't care much for > performance (probably true for an intro course). Stick the following > definitions in, say, CS101.ml > > exception Overflow > > let ( + ) a b = > let c = a + b in > if (a lxor b) lor (a lxor (lnot c)) < 0 then c else raise Overflow > ... ------------------- 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