Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: "Mattias Engdegård" <mattias@virtutech.se>
Cc: jonathan.roewen@gmail.com, pal_engstad@naughtydog.com,
	caml-list@inria.fr
Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE
Date: Fri, 08 Dec 2006 13:37:46 +1100	[thread overview]
Message-ID: <1165545466.6979.20.camel@rosella.wigram> (raw)
In-Reply-To: <200612071943.kB7JhC522308@virtutech.se>

On Thu, 2006-12-07 at 20:43 +0100, Mattias Engdegård wrote:
> >It's not a bug -- you're relying on 32bit ints when OCaml has only
> >31bit ints (on 32-bit arch). In C (for example), if you use a plain
> >int (I believe it'll default to signed), you get the exact same
> >behaviour when the number overflows 2^31.
> 
> (Signed overflow is not legal in C (undefined behaviour), and a decent
> compiler will warn this can be detected statically.)

It can be detected statically? I'd sure like to know how
(without polluting the user with hundreds of spurious warnings).

> Of course it is a bug - a design bug, since the behaviour is intended
> and documented, but still a bug. But getting numbers, even integers,
> right in every respect is hard, and involves trade-offs between
> performance, correctness and convenience.

Hmmm. In the usual full word register operations most CPU
have an overflow flag which a single conditional branch can
detect. Given branch prediction the branch is unlikely to be
taken the cost of detection is probably extremely small,
provided you have control at the assembler level.

Ocaml has slighly messier representation with one less
bit, but i guess overflow detection wouldn't be so hard
or all that expensive -- but I could be wrong, perhaps
someone on Ocaml team has looked at this can can comment?


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  parent reply	other threads:[~2006-12-08  2:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-07 18:32 Pal-Kristian Engstad
2006-12-07 19:19 ` [Caml-list] " Jonathan Roewen
2006-12-07 19:43   ` Mattias Engdegård
2006-12-07 20:02     ` Brian Hurt
2006-12-08  2:37     ` skaller [this message]
2006-12-08 11:09       ` Mattias Engdegård
2006-12-08 17:48     ` Jon Harrop
2006-12-08 18:20       ` Mattias Engdegård
2006-12-08 18:37         ` Brian Hurt
2006-12-09  2:03           ` skaller
2006-12-07 21:13 ` Martin Jambon

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=1165545466.6979.20.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=jonathan.roewen@gmail.com \
    --cc=mattias@virtutech.se \
    --cc=pal_engstad@naughtydog.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