caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Manos Renieris <er@cs.brown.edu>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: John Hughes <jfh@cs.brown.edu>, caml-list@inria.fr
Subject: Re: [Caml-list] More or bignums/ints
Date: Tue, 15 Jun 2004 18:45:38 -0400	[thread overview]
Message-ID: <20040615224538.GA6135@cs.brown.edu> (raw)
In-Reply-To: <20040614175552.A28810@pauillac.inria.fr>

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


  reply	other threads:[~2004-06-15 22:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-11 19:38 John Hughes
2004-06-12  0:09 ` Jacques Garrigue
2004-06-14 15:37 ` Brian Hurt
2004-06-14 16:17   ` Andreas Rossberg
2004-06-14 15:55 ` Xavier Leroy
2004-06-15 22:45   ` Manos Renieris [this message]
2004-06-15 20:26 ` Brian Hurt
2004-06-15 20:36   ` Brian Hurt
2004-06-23 10:50   ` John Hughes
2004-06-23 14:51     ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040615224538.GA6135@cs.brown.edu \
    --to=er@cs.brown.edu \
    --cc=caml-list@inria.fr \
    --cc=jfh@cs.brown.edu \
    --cc=xavier.leroy@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).