Re: Unsigned integers?

From: Damien Doligez (Damien.Doligez@inria.fr)
Date: Thu Mar 23 2000 - 20:42:13 MET

  • Next message: Xavier Leroy: "Re: variables in 'let rec'"

    >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



    This archive was generated by hypermail 2b29 : Fri Mar 24 2000 - 16:34:59 MET