On Mon, Jun 22, 2015 at 5:03 PM, Jarkko Hietaniemi <jhi@iki.fi> wrote: > Now, the question is, what should we do? What should we return? > > (Yes, I'm asking should we define a semantics for this thing which is > undefined in C.) > > undef? Possible, but useless. I would rather it throws an error (like division by 0) if it doesn't produce an "expected" result. > shift left by negative n == shift right by -n ? > shift right by negative n == shift left by -n? Yes, that's what I would expect a high-level language to do. It also means that $a << $b == $a * 2**$b, even for negative $b, which is again something I naively expect. :) I believe I once wrote $a << ($p-$q) and expected this generalized behaviour, but can't remember any context. > shift by too many bits == shift by n modulo wordbits? > (with a sane definition of modulo for negative -n...) Surely a right shift by too many bits should result in 0. I'm less sure about the left shift, but I think I would rather see the far left bits dropped. The modulo operation would turn the shift into a rotate, which should be a separate operator. Of course for rotation using negative numbers to change direction makes even more sense. <just kidding>Maybe <<> for rotate left and <>> for rotate right?</j/k> Cheers, -JanThread Previous | Thread Next