Circular shift (or bit rotation) is a common operation to perform and most every architecture out there has hardware support for it. Since we already use the % token to qualify existing operators with wraparound behavior, I propose we use >>%/>>%=/<<%/<<%= to denote circular shift operations.
I think the standard meaning of % elsewhere in the language (discard overflow) is kind of the opposite of this use. Other than that though I think this is worth doing. Maybe as a builtin instead?
I think the standard meaning of
%elsewhere in the language (discard overflow) is kind of the opposite of this use. Other than that though I think this is worth doing. Maybe as a builtin instead?
For addition, subtraction and multiplication with %, there is no distinction between wraparound vs. overflow/underflow, since the operations are performed modulo a power of two. The % token is described as having wrapping behavior in the docs, so that's what I went with. But if the operator is too obscure, I suppose a built-in would serve just as well.
math.rotl is only one import away, theres no need to have a thousand builtin functions for every operation.
Most helpful comment
math.rotlis only one import away, theres no need to have a thousand builtin functions for every operation.