lua-users home
lua-l archive

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


> 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[1]?
> 
>   t[1] = "int"
>   t[1.0] = "float"
>   print(t[1], t[1.0])

They are functionally equivalent, but t[1.0] can be much slower than
t[1].  (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.

-- Roberto