lua-users home
lua-l archive

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


On 11/14/12, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> I think we always stated that the main problem with bitwise operators
> in Lua was that they do not have a "natural" interpretation over Lua
> numbers. If Lua gets integers, this problem is gone.

This is a problem of implementation, not a problem of language.

IMHO, Lua would become better with introducing integer-style operations
//, /%, |, &, ^^, <<, >>, ~ and corresponding metamethods.
But I don't see the reason for introducing new data type (integer) in Lua.

Some of operations are well defined for all numbers:
a // b === floor(a/b)
a /% b === floor(a/b), a%b

Bitwise operations should return proper result for float numbers that
are in fact integers, and may do anything otherwise (non-integer
argument can be silently truncated or error can be generated depending
on implementation).

Language implementation can store additional flag "is_integer" for
float numbers (or even internally store integer numbers in integer
format instead of Double format) to speed up calculations, but such
implementation details should not be visible to programmer. Language
manual should not talk about integers as different type, thus making
language more simple.

I've always considered single numerical data type as big benefit of Lua.