<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/01/be461c4ff942cdbf26f01b18b78f15db"
  from="David Chase &lt;chase@w...&gt;"
  author="David Chase"
  date="2003-01-24T00:39:59"
  subject="Re: [Caml-list] Need unsigned int"
  prev="2003/01/4d220c5232a3b748cd9592002eec3313"
  next="2003/01/4a9754e53ff07723caf21b4496d1d267"
  prev-in-thread="2003/01/4d220c5232a3b748cd9592002eec3313"
  next-in-thread="2003/01/8ee94a5b5e46b261b7599c6003b3a18b"
  prev-thread="2003/01/a4cffb254f58984e709674a57450d264"
  next-thread="2003/01/18adbbf91ec34b35351de3a8ecc5092f"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Need unsigned int">
<msg 
  url="2003/01/72c455ab961d117e66091b9e50b158a7"
  from="Christoph Bauer &lt;c_bauer@i...&gt;"
  author="Christoph Bauer"
  date="2003-01-20T19:06:30"
  subject="[Caml-list] Need unsigned int">
<msg 
  url="2003/01/a7f0ca55dfc7972117511c4551434184"
  from="Sven Luther &lt;luther@d...&gt;"
  author="Sven Luther"
  date="2003-01-20T20:58:38"
  subject="Re: [Caml-list] Need unsigned int">
</msg>
<msg 
  url="2003/01/2f8b8c3e56cbc57ad0828a8c4c361f8a"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-01-22T13:51:49"
  subject="Re: [Caml-list] Need unsigned int">
<msg 
  url="2003/01/4d220c5232a3b748cd9592002eec3313"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2003-01-23T15:01:17"
  subject="Re: [Caml-list] Need unsigned int">
<msg 
  url="2003/01/be461c4ff942cdbf26f01b18b78f15db"
  from="David Chase &lt;chase@w...&gt;"
  author="David Chase"
  date="2003-01-24T00:39:59"
  subject="Re: [Caml-list] Need unsigned int">
</msg>
<msg 
  url="2003/01/8ee94a5b5e46b261b7599c6003b3a18b"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-01-25T12:46:27"
  subject="Re: [Caml-list] Need unsigned int">
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
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) &gt;= 0) ? (x &lt; y) : (y &lt; 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) &gt;&gt;&gt; 31) ^ (x &lt; 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&lt;x) and
(y&lt;=x) serve equally well, but (y&lt;=x) == !(x&lt;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

</contents>

</message>

