math.log now accepts an optional base

This commit is contained in:
Roberto Ierusalimschy 2006-08-07 16:01:56 -03:00
parent 33e7bc88f8
commit 5019b2dd20
1 changed files with 5 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.66 2005/08/15 14:12:32 roberto Exp roberto $
** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@ -112,7 +112,10 @@ static int math_pow (lua_State *L) {
}
static int math_log (lua_State *L) {
lua_pushnumber(L, log(luaL_checknumber(L, 1)));
lua_Number res = log(luaL_checknumber(L, 1));
if (!lua_isnoneornil(L, 2))
res /= log(luaL_checknumber(L, 2));
lua_pushnumber(L, res);
return 1;
}