lua-users home
lua-l archive

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


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

Do you mean faster execution or less typing?
I think in pure lua you will have to call a function from the math.*
library, and math.floor() is one of the fastest I think. Are you afraid
that it is not fast enough for you?

If you meant less typing, then define:

function isint(n)
  return n==math.floor(n)
end

BTW, it works for positive and negative numbers as well.

Regards,
miko