[r6rs-discuss] bitwise-rotate-bit-field count

Per Bothner per at bothner.com
Thu Jul 17 20:38:02 EDT 2008


The specification for bitwise-rotate-bit-field says:
Ei2, ei3, ei4 must be non-negative, ei2 must be less than or equal to 
ei3, and ei4 must be non-negative.

First, the requirement that ei4 (count) be non-negative is repeated.

Second, why must ei4 be non-negative?  Just like
bitwise-arithmatic-shift shifts left or right depending on the sign
of the shift amount, it seems reasonable to allow negative shifts
on a rotate.  That doesn't allow any extra functionality,
but it seems a useful convenience.  Especially since the
"reference implementation" handles negative shifts automatically,
thanks to the use the the mod operator:

(let* ((count (mod count width))

I.e. shift by (- count) bits is the same as a shift by
(- width count) bits.
-- 
	--Per Bothner
per at bothner.com   http://per.bothner.com/



More information about the r6rs-discuss mailing list