[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.3.0 (work1) now available
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sun, 7 Jul 2013 11:31:04 -0300
> On 7/5/2013 7:22 PM, Luiz Henrique de Figueiredo wrote:
> >The main change in Lua 5.3.0 is support for integers.
> Regarding numbers as table indexes in Lua 5.3, is assigning to
> t[1.0] equivalent to assigning to t?
> t = "int"
> t[1.0] = "float"
> print(t, t[1.0])
They are functionally equivalent, but t[1.0] can be much slower than
t. (The first has to check whether the float has an integer value
and, if so, convert it.)
Because we expect conversions from floats to ints to be infrequent
in Lua with integers, we took the "luxury" to make them well behaved
operations. (Always rounds towards minus infinte, raise an error if
number is out of range. We also removed several system-dependent tricks
that Lua used to speed up those conversions.)
This is something to be aware. In the few benchmarks I did, there was
a heapsort that was taking twice the time of Lua 5.2. The culprit was a
"math.floor((i+j)/2" that infected the program with floats. Changing it
to "(i+j)//2" solved the problem.