diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-28 10:39:22 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-28 10:39:22 -0200 |
| commit | 39fd5bb9b04a6a7633ddf4aa838e4909a7a0abc8 (patch) | |
| tree | c82e8d808f7b26d1c81fb0d2a652c1f51a4e5752 /lmathlib.c | |
| parent | 5482992dec286ca800ffab539b0f81eddaa2665b (diff) | |
| download | lua-39fd5bb9b04a6a7633ddf4aa838e4909a7a0abc8.tar.gz lua-39fd5bb9b04a6a7633ddf4aa838e4909a7a0abc8.tar.bz2 lua-39fd5bb9b04a6a7633ddf4aa838e4909a7a0abc8.zip | |
details
Diffstat (limited to 'lmathlib.c')
| -rw-r--r-- | lmathlib.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.4 1997/11/04 15:27:53 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.5 1997/11/19 18:16:33 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 | */ |
| @@ -13,7 +13,7 @@ | |||
| 13 | #include "lualib.h" | 13 | #include "lualib.h" |
| 14 | 14 | ||
| 15 | #ifndef PI | 15 | #ifndef PI |
| 16 | #define PI 3.14159265358979323846 | 16 | #define PI ((double)3.14159265358979323846) |
| 17 | #endif | 17 | #endif |
| 18 | 18 | ||
| 19 | 19 | ||
| @@ -24,13 +24,13 @@ | |||
| 24 | 24 | ||
| 25 | static double torad (void) | 25 | static double torad (void) |
| 26 | { | 26 | { |
| 27 | char *s = lua_getstring(lua_getglobal("_TRIGMODE")); | 27 | char *s = luaL_opt_string(2, "d"); |
| 28 | switch (*s) { | 28 | switch (*s) { |
| 29 | case 'd' : return PI/180.0; | 29 | case 'd' : return PI/180.0; |
| 30 | case 'r' : return 1.0; | 30 | case 'r' : return (double)1.0; |
| 31 | case 'g' : return PI/50.0; | 31 | case 'g' : return PI/50.0; |
| 32 | default: | 32 | default: |
| 33 | luaL_verror("invalid _TRIGMODE (`%.50s')", s); | 33 | luaL_arg_check(0, 2, "invalid mode"); |
| 34 | return 0; /* to avoid warnings */ | 34 | return 0; /* to avoid warnings */ |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| @@ -120,12 +120,12 @@ static void math_exp (void) | |||
| 120 | 120 | ||
| 121 | static void math_deg (void) | 121 | static void math_deg (void) |
| 122 | { | 122 | { |
| 123 | lua_pushnumber(luaL_check_number(1)*180./PI); | 123 | lua_pushnumber(luaL_check_number(1)*(180.0/PI)); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | static void math_rad (void) | 126 | static void math_rad (void) |
| 127 | { | 127 | { |
| 128 | lua_pushnumber(luaL_check_number(1)/180.*PI); | 128 | lua_pushnumber(luaL_check_number(1)*(PI/180.0)); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | 131 | ||
