lua-users home
lua-l archive

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


I wonder if there is an easy way of checking if the number does not exceed the precision cap BEFORE converting to some base...

On Mon, Sep 26, 2016 at 7:14 PM, Nagaev Boris <bnagaev@gmail.com> wrote:
On Mon, Sep 26, 2016 at 5:04 PM, gs <schuler.101@gmail.com> wrote:
> I am relatively new to Lua, so please bear with me.
>
> On Lua 5.2:
>> io.write(string.format("%d\n", tonumber("5c7d528b825b090", 16)));
> 416535861419946112
>
>
> On Lua 5.3:
>>  io.write(string.format("%d\n", tonumber("5c7d528b825b090", 16)));
> 416535861419946128
>
> The latter is the correct answer.
>
> (1) Am I doing something wrong in Lua 5.2. I am relatively new to Lua, and
> did not see an explicit mention of this being  fixed in 5.3 , so, I am not
> sure if there is an actual bug in 5.2.
> (2) For some reason, I can't upgrade to 5.3 (due to policies outside my
> control). Is there a workaround to get the right answer in 5.2?
>
> Thanks
>

Lua 5.2 uses floating point number (C's double) for numbers.
Lua 5.3 uses 64-bit integers as well as floating point numbers.

--


Best regards,
Boris Nagaev