lua-users home
lua-l archive

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


On Thu, Feb 23, 2017 at 12:44 AM 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?

TIL is internet shorthand for "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.

> 0x333333333333330000000000000001
1

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

Lua. The relevant logic is in lobject.c, in the function l_str2int [1], which does no checks for overflow when parsing a hex literal.

[1] https://www.lua.org/source/5.3/lobject.c.html#l_str2int