[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bug in ceillog2 macro (Lua-5.1.4)
- From: Axel Kittenberger <axkibe@...>
- Date: Fri, 7 Jan 2011 18:30:08 +0100
I propose following "patch", problem solved :-)
-------------------
@@ -51,7 +51,10 @@
else return ((x & 7) + 8) << (e - 1);
}
-
+/*
+** returns smallest exponent to 2 greater than x.
+** must be called with x > 0.
+*/
int luaO_ceillog2 (unsigned int x) {
-------------------
On Fri, Jan 7, 2011 at 4:44 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> 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
>
>