[R6RS] shift operators
dyb at cs.indiana.edu
dyb at cs.indiana.edu
Wed Mar 29 16:26:39 EST 2006
Three fixnum shift operators and one exact operator are listed:
fxarithmetic-shift-left
fxlogical-shift-left
fxlogical-shift-right
exact-arithmetic-shift-left
negative shift counts are allowed for the arithmetic operators, but "all
bets are off" when the count argument is negative for the logical
operators. This seems inconsistent and a bit bizarre.
Furthermore, handling negative arguments will require an extra test and
branch on most machines, and for the fixnum operators, handling count
arguments greater than the number of bits in a fixnum will require an
additional test and branch.
These procedures would be more useful when used in compute intensive
programs, if:
- the direction of the shift is implied by the name
- the count is always nonnegative
- the count is not more than the number of fixnum bits
These issues aren't as important for the exact operators, but we should
probably keep them consistent with the fixnum operators. So I propose:
fxarithmetic-shift-left
fxarithmetic-shift-right
fxlogical-shift-left
fxlogical-shift-right
exact-arithmetic-shift-left
exact-arithmetic-shift-right
where each raises an exception if the count argument is negative, and each
of the fixnum versions raise an exception if the count argument is greater
than the number of bits in a fixnum.
Kent
More information about the R6RS
mailing list