better precision for log(x, 10)
This commit is contained in:
14
lmathlib.c
14
lmathlib.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lmathlib.c,v 1.69 2007/03/27 12:37:00 roberto Exp roberto $
|
** $Id: lmathlib.c,v 1.70 2007/06/21 13:48:04 roberto Exp roberto $
|
||||||
** Standard mathematical library
|
** Standard mathematical library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -112,9 +112,15 @@ static int math_pow (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int math_log (lua_State *L) {
|
static int math_log (lua_State *L) {
|
||||||
lua_Number res = log(luaL_checknumber(L, 1));
|
lua_Number x = luaL_checknumber(L, 1);
|
||||||
if (!lua_isnoneornil(L, 2))
|
lua_Number res;
|
||||||
res /= log(luaL_checknumber(L, 2));
|
if (lua_isnoneornil(L, 2))
|
||||||
|
res = log(x);
|
||||||
|
else {
|
||||||
|
lua_Number base = luaL_checknumber(L, 2);
|
||||||
|
if (base == 10.0) res = log10(x);
|
||||||
|
else res = log(x)/log(base);
|
||||||
|
}
|
||||||
lua_pushnumber(L, res);
|
lua_pushnumber(L, res);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user