lua-users home
lua-l archive

Re: Bitwise XOR in Lua?

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


Roberto Ierusalimschy wrote:
> 
> > But de Morganising makes bor use four calls to band (three via bnot), so
> > to avoid that I kept bor primitive.
> 
> You forgot the other "bunny" (whatever that means ;-):
> 
> > not A = -A - 1 (Paul Hsieh wrote that)
> 
> So, you have
> 
> function bor (a,b) return -band(-a-1, -b-1)-1 end
One problem though: -A := not(A)+1 is for 2-complement.
Floating point numbers (normally) do not use 2-complement
arithmetic.
Ciao, ET.

AltStyle によって変換されたページ (->オリジナル) /