diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-08-07 16:01:56 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-08-07 16:01:56 -0300 |
| commit | 5019b2dd205751c6f29c4ced2b6f1e22c096fb83 (patch) | |
| tree | a0dd847b5eea1e541160303af4c882c63a3f7fff | |
| parent | 33e7bc88f866500ebcc3ba7e71c09fefa184fc69 (diff) | |
| download | lua-5019b2dd205751c6f29c4ced2b6f1e22c096fb83.tar.gz lua-5019b2dd205751c6f29c4ced2b6f1e22c096fb83.tar.bz2 lua-5019b2dd205751c6f29c4ced2b6f1e22c096fb83.zip | |
math.log now accepts an optional base
| -rw-r--r-- | lmathlib.c | 7 |
1 files changed, 5 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.66 2005/08/15 14:12:32 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.67 2005/08/26 17:36:32 roberto Exp roberto $ |
| 3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -112,7 +112,10 @@ static int math_pow (lua_State *L) { | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | static int math_log (lua_State *L) { | 114 | static int math_log (lua_State *L) { |
| 115 | lua_pushnumber(L, log(luaL_checknumber(L, 1))); | 115 | lua_Number res = log(luaL_checknumber(L, 1)); |
| 116 | if (!lua_isnoneornil(L, 2)) | ||
| 117 | res /= log(luaL_checknumber(L, 2)); | ||
| 118 | lua_pushnumber(L, res); | ||
| 116 | return 1; | 119 | return 1; |
| 117 | } | 120 | } |
| 118 | 121 | ||
