diff options
-rw-r--r-- | lmathlib.c | 12 | ||||
-rw-r--r-- | loslib.c | 5 |
2 files changed, 9 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.108 2014/07/28 17:35:47 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.109 2014/10/01 11:54:56 roberto Exp $ |
3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -153,7 +153,7 @@ static int math_modf (lua_State *L) { | |||
153 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); | 153 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); |
154 | pushnumint(L, ip); | 154 | pushnumint(L, ip); |
155 | /* fractional part (test needed for inf/-inf) */ | 155 | /* fractional part (test needed for inf/-inf) */ |
156 | lua_pushnumber(L, (n == ip) ? 0.0 : (n - ip)); | 156 | lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip)); |
157 | } | 157 | } |
158 | return 2; | 158 | return 2; |
159 | } | 159 | } |
@@ -192,12 +192,12 @@ static int math_exp (lua_State *L) { | |||
192 | } | 192 | } |
193 | 193 | ||
194 | static int math_deg (lua_State *L) { | 194 | static int math_deg (lua_State *L) { |
195 | lua_pushnumber(L, luaL_checknumber(L, 1) * (180.0 / PI)); | 195 | lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI)); |
196 | return 1; | 196 | return 1; |
197 | } | 197 | } |
198 | 198 | ||
199 | static int math_rad (lua_State *L) { | 199 | static int math_rad (lua_State *L) { |
200 | lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / 180.0)); | 200 | lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0))); |
201 | return 1; | 201 | return 1; |
202 | } | 202 | } |
203 | 203 | ||
@@ -239,7 +239,7 @@ static int math_random (lua_State *L) { | |||
239 | double r = (double)l_rand() * (1.0 / ((double)RAND_MAX + 1.0)); | 239 | double r = (double)l_rand() * (1.0 / ((double)RAND_MAX + 1.0)); |
240 | switch (lua_gettop(L)) { /* check number of arguments */ | 240 | switch (lua_gettop(L)) { /* check number of arguments */ |
241 | case 0: { /* no arguments */ | 241 | case 0: { /* no arguments */ |
242 | lua_pushnumber(L, r); /* Number between 0 and 1 */ | 242 | lua_pushnumber(L, (lua_Number)r); /* Number between 0 and 1 */ |
243 | return 1; | 243 | return 1; |
244 | } | 244 | } |
245 | case 1: { /* only upper limit */ | 245 | case 1: { /* only upper limit */ |
@@ -389,7 +389,7 @@ LUAMOD_API int luaopen_math (lua_State *L) { | |||
389 | luaL_newlib(L, mathlib); | 389 | luaL_newlib(L, mathlib); |
390 | lua_pushnumber(L, PI); | 390 | lua_pushnumber(L, PI); |
391 | lua_setfield(L, -2, "pi"); | 391 | lua_setfield(L, -2, "pi"); |
392 | lua_pushnumber(L, HUGE_VAL); | 392 | lua_pushnumber(L, (lua_Number)HUGE_VAL); |
393 | lua_setfield(L, -2, "huge"); | 393 | lua_setfield(L, -2, "huge"); |
394 | lua_pushinteger(L, LUA_MAXINTEGER); | 394 | lua_pushinteger(L, LUA_MAXINTEGER); |
395 | lua_setfield(L, -2, "maxinteger"); | 395 | lua_setfield(L, -2, "maxinteger"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loslib.c,v 1.46 2014/04/29 17:05:13 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.47 2014/10/01 11:54:56 roberto Exp roberto $ |
3 | ** Standard Operating System library | 3 | ** Standard Operating System library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -295,7 +295,8 @@ static int os_time (lua_State *L) { | |||
295 | 295 | ||
296 | 296 | ||
297 | static int os_difftime (lua_State *L) { | 297 | static int os_difftime (lua_State *L) { |
298 | lua_pushnumber(L, difftime((l_checktime(L, 1)), (l_checktime(L, 2)))); | 298 | double res = difftime((l_checktime(L, 1)), (l_checktime(L, 2))); |
299 | lua_pushnumber(L, (lua_Number)res); | ||
299 | return 1; | 300 | return 1; |
300 | } | 301 | } |
301 | 302 | ||