lua-users home
lua-l archive

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


On 21 May 2016 at 14:51, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:
On Wed, May 18, 2016 at 4:04 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
One problem with all proposed solutions is math.mininteger. The
lexer reads numbers without signal. (Several languages do the
same, e.g. C).  This means that -9223372036854775808 is read as
-(9223372036854775808) (a unary minus applied over a positive
constant). But 9223372036854775808 is not a valid integer, so it would
result in a float (or nil, or inf, or error). Whatever the choice, the
final value of -9223372036854775808 would not be an integer, despite
it being a valid integer.

BTW, if user has redefined numeric operations,
how do you decide the way the following Lua code should be interpreted:
x=-9223372036854775808
Which of the following two variants it is equivalent to:
x=math.mininteger
or
x=getmetatable(0).__unm(9223372036854775808)

metamethods are not overrides. they are fallbacks.
Math operations *cannot* be overridden on numbers.