lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It was thus said that the Great Stefan Ginsberg once stated:
> > On 15 May 2017, at 01:13, Sean Conner <> wrote:
> > 
> > Shifting is just multiplication or division by two.  At the CPU level,
> > there is a distinction made between shifts (left (multiplication) which
> > shifts in 0s and right (division) which shifts in the sign bit) and rotates
> > (shifts the bits, rotating in the carry bit).
> > 
> > -spc
> What I really meant is that a shift operator which disallows shifting out
> (all) bits would be less-than-useful.

  I'm still confused.  Ignoring rotates (which rotate the bits) CPUs tend to
support two forms of shifting, an unsigned variant (where 0 is copied in for
right shifts) and a signed variant (where the sign bit is copied for right
shifts) and are (nominally) used for multiplication/division by 2, which
makes it an arithmetic operation, and which I use to replace certain
exponential operations I used from Lua 5.1/5.2:

	x = 2^30	-- Lua 5.1, 5.2 to get 1073741824

	x = 1<<30	-- Lua 5.3 to get 1073741824