Sfoglia il codice sorgente

math.log now accepts an optional base

Roberto Ierusalimschy 19 anni fa
parent
commit
5019b2dd20
1 ha cambiato i file con 5 aggiunte e 2 eliminazioni
  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
 ** 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;
 }