lua-users home
lua-l archive

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


David Jones wrote:
Roberto Ierusalimschy wrote:
Essentially any bitwise operation gets converted to a series of arithmetical operations,

That is all we wanted for Lua. But "not" and shifts are easy. Can you
give a viable implementation for or/and?

Well, I was talking about specifying the meaning. As for an implementation, choose the simple portable approach: convert the number to your favourite, C, integer type, do the operation in that type, then convert back to whatever type you've chosen for numbers. Sticking to double (for numbers) and int (for integers) and doing this gives you a portable 32-bit implementation. luaconf.h helps those who want more.


Or were you thinking of an approach where you change only the compiler and not the VM? You can't reasonably do that, the implementation of "bitwise-and" is too tedious. However with just "bitwise-and" or "bitwise-or" you can do all the others.

drj