shr(x,n) and lshr(x,n) have always handled shift values outside the 0…31 range in a peculiar way: negative values of n are treated like n&31, while values ≥ 32 always return 0 (or 0xffff.ffff for a signed shift).
But now the new >>> operator diverges from lshr by treating n ≥ 32 like n&31, so we get:
1 >> 32 = 0 shr(1,32) = 0 1 >>> 32 = 1 lshr(1,32) = 0
edit: same with << which no longer behaves like shl()
Thanks @samhocevar, that was a timely catch -- fixed for 0.2.0f
I think it's worth the low risk of breakage to do something better for negative shift values too. To follow suit with the n >= 32 behaviour I suppose shl(x, -n) should give the same result as lshr(x, n) and vice versa, as Lua 5.3 does. It's not the best for porting / transpiling to non-Lua languages, but oh well.
[Please log in to post a comment]