From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: "Krishnaswami, Neel" <neelk@cswcasa.com>
Cc: "'caml-list@inria.fr'" <caml-list@inria.fr>
Subject: Re: [Caml-list] Ints and overflow...
Date: Sun, 15 Jul 2001 13:17:12 +0200 [thread overview]
Message-ID: <20010715131712.A4478@pauillac.inria.fr> (raw)
In-Reply-To: <B1E4D3274D57D411BE8400D0B783FF322E8661@exchange1.cswv.com>; from neelk@cswcasa.com on Fri, Jul 13, 2001 at 03:25:19PM -0400
> 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
prev parent reply other threads:[~2001-07-15 11:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-13 19:25 Krishnaswami, Neel
2001-07-15 11:17 ` Xavier Leroy [this message]
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=20010715131712.A4478@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=neelk@cswcasa.com \
/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