lua-users home
lua-l archive

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


On 23 February 2017 at 16:43, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2017-02-23 2:45 GMT+02:00 Daurnimator <quae@daurnimator.com>:
>
>> TIL that hex literals don't overflow into floats:
>
> What is TIL supposed to mean in this context?

Today I Learned.


>> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>>> 0x7fffffffffffffff
>> 9223372036854775807
>>> 0x7ffffffffffffffff
>> -1
>>> 0x7fffffffffffffffff
>> -1
>>> 0x2222222222222222
>
> It looks as if the last 16 hex digits are kept and the
> rest ignored. Not a clever option for decimal.

It overflows (a C unsigned integer, and hence we get wrap-around semantics).

>> 0x333333333333330000000000000001
> 1
>
> One could look at the Lua source to see whether it is a Lua
> or a C feature.
>

It's due to l_str2int
(https://www.lua.org/source/5.3/lobject.c.html#l_str2int) not having
an overflow check in the hex case.