diff options
author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-15 11:13:44 -0300 |
---|---|---|
committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1994-08-15 11:13:44 -0300 |
commit | f490b1bff8628b4de0acdfbeb06b247f1ceb8345 (patch) | |
tree | 34e4aab0f9e61e099d9a389377bf16157254dc08 | |
parent | 3921b43e44a47334efd6da5c48e151cb3ad2fa96 (diff) | |
download | lua-f490b1bff8628b4de0acdfbeb06b247f1ceb8345.tar.gz lua-f490b1bff8628b4de0acdfbeb06b247f1ceb8345.tar.bz2 lua-f490b1bff8628b4de0acdfbeb06b247f1ceb8345.zip |
Implementacao das funcoes 'log', 'log10' e 'exp'.
-rw-r--r-- | mathlib.c | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_mathlib="$Id: mathlib.c,v 1.1 1993/12/17 18:41:19 celes Exp celes $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.2 1994/07/20 22:12:27 celes Exp celes $"; |
7 | 7 | ||
8 | #include <stdio.h> /* NULL */ | 8 | #include <stdio.h> /* NULL */ |
9 | #include <math.h> | 9 | #include <math.h> |
@@ -214,6 +214,43 @@ static void math_max (void) | |||
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | static void math_log (void) | ||
218 | { | ||
219 | double d; | ||
220 | lua_Object o = lua_getparam (1); | ||
221 | if (o == NULL) | ||
222 | { lua_error ("too few arguments to function `log'"); return; } | ||
223 | if (!lua_isnumber(o)) | ||
224 | { lua_error ("incorrect arguments to function `log'"); return; } | ||
225 | d = lua_getnumber(o); | ||
226 | lua_pushnumber (log(d)); | ||
227 | } | ||
228 | |||
229 | |||
230 | static void math_log10 (void) | ||
231 | { | ||
232 | double d; | ||
233 | lua_Object o = lua_getparam (1); | ||
234 | if (o == NULL) | ||
235 | { lua_error ("too few arguments to function `log10'"); return; } | ||
236 | if (!lua_isnumber(o)) | ||
237 | { lua_error ("incorrect arguments to function `log10'"); return; } | ||
238 | d = lua_getnumber(o); | ||
239 | lua_pushnumber (log10(d)); | ||
240 | } | ||
241 | |||
242 | |||
243 | static void math_exp (void) | ||
244 | { | ||
245 | double d; | ||
246 | lua_Object o = lua_getparam (1); | ||
247 | if (o == NULL) | ||
248 | { lua_error ("too few arguments to function `exp'"); return; } | ||
249 | if (!lua_isnumber(o)) | ||
250 | { lua_error ("incorrect arguments to function `exp'"); return; } | ||
251 | d = lua_getnumber(o); | ||
252 | lua_pushnumber (exp(d)); | ||
253 | } | ||
217 | 254 | ||
218 | /* | 255 | /* |
219 | ** Open math library | 256 | ** Open math library |
@@ -234,4 +271,7 @@ void mathlib_open (void) | |||
234 | lua_register ("pow", math_pow); | 271 | lua_register ("pow", math_pow); |
235 | lua_register ("min", math_min); | 272 | lua_register ("min", math_min); |
236 | lua_register ("max", math_max); | 273 | lua_register ("max", math_max); |
274 | lua_register ("log", math_log); | ||
275 | lua_register ("log10", math_log10); | ||
276 | lua_register ("exp", math_exp); | ||
237 | } | 277 | } |