[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Integer Shift Function(s)



    Date: Wed, 16 Apr 1986  22:28 EST
    From: "Scott E. Fahlman" <Fahlman@C.CS.CMU.EDU>

[This looks like a reply.]


    All of the logical operations are defined in terms of an abstract
    integer type that is infinitely sign-extended to the left.  That way,
    the machine's word-length, or the length of the data part of its fixnum
    representation, is hidden.  What would a logical shift operation (or a
    rotate, though you don't ask about that) do in this context?

I agree, it can't do anything.

    An implementation may want to define LSH and ROT operations for its own
    peculiar fixnum length, but such a thing makes no sense in portable
    code.

JonL, at one point, suggested abstract LSH and ROT operations that take
a third argument which is the pretend-I'm-a-fixnum-length.  Thus,
	(rot  1 -1 5) == (ash -1 4) == -16.
	(lsh -1 -1 6) == #2r011111 == 31.
Personally, I think this is cute, but probably not extrememly practical.

Also note: I think you will find most uses of LSH and ROT (for those
extended Common Lisps that implement them) are almost exclusively inside
operating system code.