[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Definion of 'for' statement in the manual
- From: Coda Highland <chighland@...>
- Date: Sat, 26 Sep 2015 11:35:19 -0700
On Sat, Sep 26, 2015 at 11:32 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> >> Why does Lua 5.3's reference does "var = var - step" instead of simply
>> >> moving the "var = var + step" after "block" (as in Lua 5.2)?
>> >
>> > This is how it is implemented, and both ways can give different results.
>> > (That it is why we do not like to specify things with code, it gives too
>> > much details that should be left open.)
>>
>> How could both ways give different results?
>
> Floating point operations. See the next example:
>
> > for i = -2^53, -2^53 + 2 do print(string.format("%.0f", i)) end
> -9007199254740991
> -9007199254740990
>
> (Note that the given initial value, -2^53, is -9007199254740992.)
>
> -- Roberto
>
Huh. I'm surprised that's not using int64 since it's Lua 5.3, unless
tonumber() is expressly asking for a double conversion. I wouldn't
have expected this behavior.
/s/ Adam