lua-users home
lua-l archive

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

On 4/22/2013 10:11 AM, Coda Highland wrote:
On Sun, Apr 21, 2013 at 6:45 PM, KHMan wrote:
On 4/22/2013 4:26 AM, [ex] wrote:

I'm using Lua 5.2 as the foundation of my own language (Killa).
Killa has a JavaScript like syntax and hence supports:

       alert(9.9 | 0); // Alerts 9. (x|0) is used a lot in JS to
floor x.

the code in Lua:

       print(bit32.bor(9.9, 0)) -- prints 10, not 9

JavaScript should have fixed this kind of defect, they had ample releases to
do so. Non-integers for a bitwise function? This is like texting while
driving... :-)

Just use math.floor in Lua.

This *is* the way JS fixed it. Bitwise operations coerce to integer,
and x|0 is a lot faster than Math.floor(x), plus also the bitop gives
JIT optimizers a very powerful hint that the value is an integer and
will probably always be one.

Disappointing... having read old javascript specs, I guess I am not surprised ;-)

Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia