Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Need unsigned int
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] Need unsigned int
> my program need to calculate a hash key of a matrix (with dimension 8
> x 8).  It is necessary that this calculation is very fast, so my
> program will update the hash key after every small modification of the
> matrix. My problem is that the hash key should be an unsigned int
> or an unsigned long in.
> My problem occurs here (Mersenne prime number 2^31-1):
> let big_prim = 2147483647
> val big_prim : int = -1

OCaml does not of unsigned integers.
Using Int64 or Bignum modules as Sven suggested you would be a threat to
your program performances since it involves boxing.

BTW, why do care about the integer sign ?
Only the printer show you -1, but the hardware representation, taking note
that OCaml int are 31 bits, doesn't change between signed and unsigned, does
it ? The only main difference I see is when comparing two signed integers.
Then perhaps something like :

let ui_compare x y =
    x lsr 16 < y lsr 16 || x land 0xFFFF < y land 0xFFFF

Is what you need.

ui_compare 1 2;; // true
ui_compare (-1) 2;; // false

Nicolas Cannasse

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: