lua-users home
lua-l archive

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


> Hi List,
> In Lua-5.1.4 macro
> 
> #define ceillog2(x)	(luaO_log2((x)-1) + 1)
> 
> gives wrong answer when x is 0.
> ceillog2(0) => 32 (should be 1).
> 
> I attached below a standalone code snippet to demonstrate the problem.
> I use Lua-5.1.4 on Ubuntu-9.04 x86 (32 bits).
> There are several  ways to fix it and I like _none_ of them.
> 
> (1) Ignore the bug. Just make sure that x>0 always.
> 
> [...]

This is an internal function; it is not for general use. It cannot be
called with a zero argument (see the calling points). It should not be
called with a zero argument, because math.ceil(math.log(0, 2)) is -inf
anyway.

Where is the bug?

-- Roberto