lua-users home
lua-l archive

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


Alexander Gladysh wrote:
> Is there a plain Lua way to determine that given positive number is
> integer faster than doing something like a == math.floor(a)?

If 0 <= a < 2^52 then try:

  (a+2^52)-2^52 == a

Note that 2^52 is constant-folded by the parser, so this is fast,
even if it doesn't look like that.

For -2^51 < a < +2^51 try:

  (a+(2^52+2^51))-(2^52+2^51) == a

--Mike