2
0
Эх сурвалжийг харах

added some casts for the cases when lua_Number != double

Roberto Ierusalimschy 10 жил өмнө
parent
commit
65ec3379b1
2 өөрчлөгдсөн 9 нэмэгдсэн , 8 устгасан
  1. 6 6
      lmathlib.c
  2. 3 2
      loslib.c

+ 6 - 6
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");

+ 3 - 2
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;
 }