caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Chase <chase@world.std.com>
To: <caml-list@inria.fr>
Subject: Re: [Caml-list] Need unsigned int
Date: Thu, 23 Jan 2003 19:39:47 -0500	[thread overview]
Message-ID: <5.2.0.9.0.20030123193356.06829da8@pop.theWorld.com> (raw)
In-Reply-To: <74C51A70-2EE3-11D7-9F00-0003930FCE12@inria.fr>

My CAML skills are poor, especially on bitwise operations, but
here is how one does (or can do) unsigned in Java:

  public static boolean lessThan(int x, int y) {
    return ((x^y) >= 0) ? (x < y) : (y < x);
  };

That is, if the signs are the same, then signed and
unsigned compares agree.  Otherwise, the negative one
is larger.  Another way to phrase this might be (if
you hate control flow):

  return ((x^y) >>> 31) ^ (x < y);

The reasoning here is that if the signs agree, then
0 XOR any == any.  Otherwise, if the signs disagree,
then x and y are surely not equal, so (y<x) and
(y<=x) serve equally well, but (y<=x) == !(x<y),
which has a subexpression in common with the other
case.

Hope this helps.

David


 

-------------------
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:[~2003-01-24  0:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-20 19:05 Christoph Bauer
2003-01-20 20:58 ` Sven Luther
2003-01-22 14:55 ` Nicolas Cannasse
2003-01-23 15:00   ` Damien Doligez
2003-01-24  0:39     ` David Chase [this message]
2003-01-25 13:50     ` Nicolas Cannasse

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=5.2.0.9.0.20030123193356.06829da8@pop.theWorld.com \
    --to=chase@world.std.com \
    --cc=caml-list@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).