lua-users home
lua-l archive

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


Hi,

> so what are people doing in the
> interim to address this?

To test a single flag bit I once used the following (Lua 4 code, mod moved
to math.mod in Lua 5):

function testflag(x, n)  -- n should be a power of 2
    return mod(x, 2*n) >= n
end

Making mod an upvalue speeds things up slightly:

do
    local mod = mod
    function testflag(x, n)  -- n should be a power of 2
        return %mod(x, 2*n) >= n
    end
end

Bye,
Wim