diff options
| -rw-r--r-- | mathlib.c | 28 |
1 files changed, 27 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.2 1994/07/20 22:12:27 celes Exp celes $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.3 1994/08/15 14:13:44 celes Exp celes $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> /* NULL */ | 8 | #include <stdio.h> /* NULL */ |
| 9 | #include <math.h> | 9 | #include <math.h> |
| @@ -252,6 +252,30 @@ static void math_exp (void) | |||
| 252 | lua_pushnumber (exp(d)); | 252 | lua_pushnumber (exp(d)); |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | static void math_deg (void) | ||
| 256 | { | ||
| 257 | float d; | ||
| 258 | lua_Object o = lua_getparam (1); | ||
| 259 | if (o == NULL) | ||
| 260 | { lua_error ("too few arguments to function `deg'"); return; } | ||
| 261 | if (!lua_isnumber(o)) | ||
| 262 | { lua_error ("incorrect arguments to function `deg'"); return; } | ||
| 263 | d = lua_getnumber(o); | ||
| 264 | lua_pushnumber (d*180./PI); | ||
| 265 | } | ||
| 266 | |||
| 267 | static void math_rad (void) | ||
| 268 | { | ||
| 269 | float d; | ||
| 270 | lua_Object o = lua_getparam (1); | ||
| 271 | if (o == NULL) | ||
| 272 | { lua_error ("too few arguments to function `rad'"); return; } | ||
| 273 | if (!lua_isnumber(o)) | ||
| 274 | { lua_error ("incorrect arguments to function `rad'"); return; } | ||
| 275 | d = lua_getnumber(o); | ||
| 276 | lua_pushnumber (d/180.*PI); | ||
| 277 | } | ||
| 278 | |||
| 255 | /* | 279 | /* |
| 256 | ** Open math library | 280 | ** Open math library |
| 257 | */ | 281 | */ |
| @@ -274,4 +298,6 @@ void mathlib_open (void) | |||
| 274 | lua_register ("log", math_log); | 298 | lua_register ("log", math_log); |
| 275 | lua_register ("log10", math_log10); | 299 | lua_register ("log10", math_log10); |
| 276 | lua_register ("exp", math_exp); | 300 | lua_register ("exp", math_exp); |
| 301 | lua_register ("deg", math_deg); | ||
| 302 | lua_register ("rad", math_rad); | ||
| 277 | } | 303 | } |
