Browse thread
Re: Unsigned integers?
- Damien Doligez
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien Doligez <Damien.Doligez@i...> |
| Subject: | Re: Unsigned integers? |
>From: Max Skaller <maxs@in.ot.com.au> >I would be happy to replace, in this code, >evey use of 'lor', 'land', + - * < etc with >'ulor' 'uland' 'uplus' 'uminus' 'uless' etc, if only >I could define them. (I could do this in C .. but then, >I could write the below routines in C too) For ulor, uland, uplus, uminus, umult, as well as lsr and lsl, they are identical to their signed counterparts, so you don't need to do anything. For uless, since you are only ever comparing to a positive constant less than max_int, I suggest replacing "if i < constant" with "if 0 <= i && i < constant". >Note these operations MUST be extremely fast, If the above works, I doubt you can go any faster. For more complex code, you may have to use a full-blown unsigned comparison: (not tested; could be wrong) let uless x y = if (x < 0) = (y < 0) then x < y else x > y;; The only difficulty would be with division and modulo, as noted by Xavier, but I gather you don't need them for this application. -- Damien