lua-users home
lua-l archive

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



when I see the implementation of math.log and math.log10 in LuaJIT2 and in Lua 5.1 :

    LuaJIT2
        LJLIB_ASM_(math_log)            LJLIB_REC(math_unary IRFPM_LOG)
        LJLIB_ASM_(math_log10)          LJLIB_REC(math_unary IRFPM_LOG10)

    Lua 5.1.4
        static int math_log (lua_State *L) {
          lua_pushnumber(L, log(luaL_checknumber(L, 1)));
          return 1;
        }
        static int math_log10 (lua_State *L) {
          lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
          return 1;
        }

I don't understand the rational of the removal of math.log10 and the addition of optional second parameter in math.log

        Lua 5.2.0-alpha : math.log (x [, base])
        static int math_log (lua_State *L) {
          lua_Number x = luaL_checknumber(L, 1);
          lua_Number res;
          if (lua_isnoneornil(L, 2))
            res = l_tg(log)(x);
          else {
            lua_Number base = luaL_checknumber(L, 2);
            if (base == 10.0) res = l_tg(log10)(x);
            else res = l_tg(log)(x)/l_tg(log)(base);
          }
          lua_pushnumber(L, res);
          return 1;
        }

It's a general implementation of log, but all opportunities of optimization are lost.

François