lua-users home
lua-l archive

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


ceillog of 0.5 is -1
ceillog of 0.25 is -2
ceillog of 0.125 is -3
etc

Am 07.01.2011 16:09 schrieb "Leo Razoumov" <slonik.az@gmail.com>:
>
> 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--
>