[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.3 precedence issue
- From: Pierpaolo Bernardi <olopierpa@...>
- Date: Sat, 17 Jan 2015 09:26:32 +0100
What is the issue? Can you be more explicit?
On Sat, Jan 17, 2015 at 9:17 AM, Dmitry V. Zaitsev <hhrhhr@gmail.com> wrote:
> from manual:
>
>> Operator precedence in Lua follows the table below, from lower to higher
>> priority:
>> [[cut]]
>> << >>
>> ..
>> + -
>> * / // %
>> [[cut]]
>
>
> test example with wrong result:
>
>> Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
>> > i = 0
>> > i = i + 1 * 1 << 8
>> > print(i)
>> 256
>> > i = i + 1 * 1 << 16
>> > print(i)
>> 16842752
>> > i = i + 1 * 1 << 24
>> > print(i)
>> 282574505115648
>
>
> but with braces all ok:
>
>> Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
>> > i = 0
>> > i = i + 1 * (1 << 8)
>> > print(i)
>> 256
>> > i = i + 1 * (1 << 16)
>> > print(i)
>> 65792
>> > i = i + 1 * (1 << 24)
>> > print(i)
>> 16843008