[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Fastest way to determine number is integer in plain Lua**
**From**: Mike Pall <mikelu-0811@...>
**Date**: Fri, 7 Nov 2008 16:58:16 +0100

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