[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Overflow of hex vs decimal integer literals
- From: Daurnimator <quae@...>
- Date: Thu, 23 Feb 2017 17:21:13 +1100
On 23 February 2017 at 16:43, Dirk Laurie <firstname.lastname@example.org> wrote:
> 2017-02-23 2:45 GMT+02:00 Daurnimator <email@example.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
> 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).
> 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.