lua-users home
lua-l archive

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


2014-03-04 13:43 GMT+02:00 Dio Darkclainer <darkclainer@gmail.com>:

> for i=1,20 do
>    if math.floor(math.log(2^i,2)) ~= i then
>       print(i)
>    end
> end
>
> will be output
> 3
> 6
> 12
> 13

The C code in lmathlib.c says:

    res = l_mathop(log)(x)/l_mathop(log)(base)

There is nothing special about base=2, so you get the
usual implementation-dependent errors.

If Lua allowed itself the use of C99, we could have had

    res = l_mathop(log2)(x)/l_mathop(log2)(base)

which would be exact.

> if use math.log(2^i)/math.log(2) instead all work correctly

Does it continue working correctly if you increase the upper
bound of the loo[?