diff options
Diffstat (limited to 'lmathlib.c')
| -rw-r--r-- | lmathlib.c | 25 |
1 files changed, 6 insertions, 19 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.5 1997/11/19 18:16:33 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.6 1997/11/28 12:39:22 roberto Exp roberto $ |
| 3 | ** Lua standard mathematical library | 3 | ** Lua standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -12,28 +12,15 @@ | |||
| 12 | #include "lua.h" | 12 | #include "lua.h" |
| 13 | #include "lualib.h" | 13 | #include "lualib.h" |
| 14 | 14 | ||
| 15 | #ifndef PI | 15 | #ifdef M_PI |
| 16 | #define PI M_PI | ||
| 17 | #else | ||
| 16 | #define PI ((double)3.14159265358979323846) | 18 | #define PI ((double)3.14159265358979323846) |
| 17 | #endif | 19 | #endif |
| 18 | 20 | ||
| 19 | 21 | ||
| 20 | 22 | #define FROMRAD(a) ((a)*(180.0/PI)) | |
| 21 | #define FROMRAD(a) ((a)/torad()) | 23 | #define TORAD(a) ((a)*(PI/180.0)) |
| 22 | #define TORAD(a) ((a)*torad()) | ||
| 23 | |||
| 24 | |||
| 25 | static double torad (void) | ||
| 26 | { | ||
| 27 | char *s = luaL_opt_string(2, "d"); | ||
| 28 | switch (*s) { | ||
| 29 | case 'd' : return PI/180.0; | ||
| 30 | case 'r' : return (double)1.0; | ||
| 31 | case 'g' : return PI/50.0; | ||
| 32 | default: | ||
| 33 | luaL_arg_check(0, 2, "invalid mode"); | ||
| 34 | return 0; /* to avoid warnings */ | ||
| 35 | } | ||
| 36 | } | ||
| 37 | 24 | ||
| 38 | 25 | ||
| 39 | static void math_abs (void) | 26 | static void math_abs (void) |
