Browse Source

math.log now accepts an optional base

Roberto Ierusalimschy 19 years ago
parent
commit
5019b2dd20
1 changed files with 5 additions and 2 deletions
  1. 5 2
      lmathlib.c

+ 5 - 2
lmathlib.c

@@ -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
 ** Standard mathematical library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -112,7 +112,10 @@ static int math_pow (lua_State *L) {
 }
 }
 
 
 static int math_log (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;
   return 1;
 }
 }