lua-users home
lua-l archive

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


On Fri, Jan 7, 2011 at 09:57, liam mail <liam.list@googlemail.com> wrote:
>
> Unless my maths fails me isn't log2(0) infinity or undefined?
> Liam
>

Mathematically, log2(0) is negative infinity. But here we talk about
ceillog2 function which is a ceiling by nearest power of two. Also
luaO_log2(x) implementation via shifts and integer table lookups makes
it mathematically quite different from, real log2 function.

For any non-negative integer x minimal number of bits to store x is
ceillog2(x)+1. And this is the practical meaning of ceillog2 in Lua
context.

--Leo--