From 65ec3379b10654f49b7faaf841b308b0cbb7b68b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 8 Oct 2014 16:57:31 -0300 Subject: [PATCH] added some casts for the cases when lua_Number != double --- lmathlib.c | 12 ++++++------ loslib.c | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lmathlib.c b/lmathlib.c index 59e529cb..974c7280 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -1,5 +1,5 @@ /* -** $Id: lmathlib.c,v 1.108 2014/07/28 17:35:47 roberto Exp roberto $ +** $Id: lmathlib.c,v 1.109 2014/10/01 11:54:56 roberto Exp $ ** Standard mathematical library ** See Copyright Notice in lua.h */ @@ -153,7 +153,7 @@ static int math_modf (lua_State *L) { lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); pushnumint(L, ip); /* fractional part (test needed for inf/-inf) */ - lua_pushnumber(L, (n == ip) ? 0.0 : (n - ip)); + lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip)); } return 2; } @@ -192,12 +192,12 @@ static int math_exp (lua_State *L) { } static int math_deg (lua_State *L) { - lua_pushnumber(L, luaL_checknumber(L, 1) * (180.0 / PI)); + lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI)); return 1; } static int math_rad (lua_State *L) { - lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / 180.0)); + lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0))); return 1; } @@ -239,7 +239,7 @@ static int math_random (lua_State *L) { double r = (double)l_rand() * (1.0 / ((double)RAND_MAX + 1.0)); switch (lua_gettop(L)) { /* check number of arguments */ case 0: { /* no arguments */ - lua_pushnumber(L, r); /* Number between 0 and 1 */ + lua_pushnumber(L, (lua_Number)r); /* Number between 0 and 1 */ return 1; } case 1: { /* only upper limit */ @@ -389,7 +389,7 @@ LUAMOD_API int luaopen_math (lua_State *L) { luaL_newlib(L, mathlib); lua_pushnumber(L, PI); lua_setfield(L, -2, "pi"); - lua_pushnumber(L, HUGE_VAL); + lua_pushnumber(L, (lua_Number)HUGE_VAL); lua_setfield(L, -2, "huge"); lua_pushinteger(L, LUA_MAXINTEGER); lua_setfield(L, -2, "maxinteger"); diff --git a/loslib.c b/loslib.c index 209e74cd..47d1a6eb 100644 --- a/loslib.c +++ b/loslib.c @@ -1,5 +1,5 @@ /* -** $Id: loslib.c,v 1.46 2014/04/29 17:05:13 roberto Exp roberto $ +** $Id: loslib.c,v 1.47 2014/10/01 11:54:56 roberto Exp roberto $ ** Standard Operating System library ** See Copyright Notice in lua.h */ @@ -295,7 +295,8 @@ static int os_time (lua_State *L) { static int os_difftime (lua_State *L) { - lua_pushnumber(L, difftime((l_checktime(L, 1)), (l_checktime(L, 2)))); + double res = difftime((l_checktime(L, 1)), (l_checktime(L, 2))); + lua_pushnumber(L, (lua_Number)res); return 1; }