commit a8aede68c749c554ef5368f31550812f7a9a345a
parent c7859a046ded0eaca74a4412b03fc657d6d9ab4d
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 9 Apr 2014 14:04:46 -0300
new definition for 'luai_nummod' (using 'fmod')
Diffstat:
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/lobject.c b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 2.75 2014/03/06 16:15:18 roberto Exp roberto $
+** $Id: lobject.c,v 2.76 2014/03/21 13:52:33 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -98,9 +98,13 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1,
case LUA_OPSUB: return luai_numsub(L, v1, v2);
case LUA_OPMUL: return luai_nummul(L, v1, v2);
case LUA_OPDIV: return luai_numdiv(L, v1, v2);
- case LUA_OPMOD: return luai_nummod(L, v1, v2);
case LUA_OPPOW: return luai_numpow(L, v1, v2);
case LUA_OPUNM: return luai_numunm(L, v1);
+ case LUA_OPMOD: {
+ lua_Number m;
+ luai_nummod(L, v1, v2, m);
+ return m;
+ }
default: lua_assert(0); return 0;
}
}
diff --git a/luaconf.h b/luaconf.h
@@ -1,5 +1,5 @@
/*
-** $Id: luaconf.h,v 1.193 2014/03/21 14:27:16 roberto Exp roberto $
+** $Id: luaconf.h,v 1.194 2014/04/03 14:18:02 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@@ -497,7 +497,8 @@
/* the following operations need the math library */
#if defined(lobject_c) || defined(lvm_c)
#include <math.h>
-#define luai_nummod(L,a,b) ((void)L, (a) - l_floor((a)/(b))*(b))
+#define luai_nummod(L,a,b,m) \
+ { (m) = l_mathop(fmod)(a,b); if ((m) != 0 && (a)*(b) < 0) (m) += (b); }
#define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b))
#endif
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 2.193 2014/04/02 16:54:20 roberto Exp roberto $
+** $Id: lvm.c,v 2.194 2014/04/08 14:28:04 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -755,7 +755,9 @@ void luaV_execute (lua_State *L) {
setivalue(ra, luaV_mod(L, ib, ic));
}
else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {
- setnvalue(ra, luai_nummod(L, nb, nc));
+ lua_Number m;
+ luai_nummod(L, nb, nc, m);
+ setnvalue(ra, m);
}
else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); }
)