Browse thread
[Caml-list] More or bignums/ints
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Manos Renieris <er@c...> |
| Subject: | Re: [Caml-list] More or bignums/ints |
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