summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-08 16:57:31 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-10-08 16:57:31 -0300
commit65ec3379b10654f49b7faaf841b308b0cbb7b68b (patch)
tree7e8acbb37ec5f38c018b2fd35270d419d562f3d1
parent85fc9ecd5f5d2af63d48f6ac2bb46217e3fa6a04 (diff)
downloadlua-65ec3379b10654f49b7faaf841b308b0cbb7b68b.tar.gz
lua-65ec3379b10654f49b7faaf841b308b0cbb7b68b.tar.bz2
lua-65ec3379b10654f49b7faaf841b308b0cbb7b68b.zip
added some casts for the cases when lua_Number != double
-rw-r--r--lmathlib.c12
-rw-r--r--loslib.c5
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 @@
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
194static int math_deg (lua_State *L) { 194static 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
199static int math_rad (lua_State *L) { 199static 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");
diff --git a/loslib.c b/loslib.c
index 209e74cd..47d1a6eb 100644
--- a/loslib.c
+++ b/loslib.c
@@ -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
297static int os_difftime (lua_State *L) { 297static 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