diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-09 14:05:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-04-09 14:05:11 -0300 |
commit | a8aede68c749c554ef5368f31550812f7a9a345a (patch) | |
tree | 8cc99ff1fad328746a3168367f1d57d60a9fbb14 | |
parent | c7859a046ded0eaca74a4412b03fc657d6d9ab4d (diff) | |
download | lua-a8aede68c749c554ef5368f31550812f7a9a345a.tar.gz lua-a8aede68c749c554ef5368f31550812f7a9a345a.tar.bz2 lua-a8aede68c749c554ef5368f31550812f7a9a345a.zip |
new definition for 'luai_nummod' (using 'fmod')
-rw-r--r-- | lobject.c | 8 | ||||
-rw-r--r-- | luaconf.h | 5 | ||||
-rw-r--r-- | lvm.c | 6 |
3 files changed, 13 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 2.75 2014/03/06 16:15:18 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.76 2014/03/21 13:52:33 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -98,9 +98,13 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1, | |||
98 | case LUA_OPSUB: return luai_numsub(L, v1, v2); | 98 | case LUA_OPSUB: return luai_numsub(L, v1, v2); |
99 | case LUA_OPMUL: return luai_nummul(L, v1, v2); | 99 | case LUA_OPMUL: return luai_nummul(L, v1, v2); |
100 | case LUA_OPDIV: return luai_numdiv(L, v1, v2); | 100 | case LUA_OPDIV: return luai_numdiv(L, v1, v2); |
101 | case LUA_OPMOD: return luai_nummod(L, v1, v2); | ||
102 | case LUA_OPPOW: return luai_numpow(L, v1, v2); | 101 | case LUA_OPPOW: return luai_numpow(L, v1, v2); |
103 | case LUA_OPUNM: return luai_numunm(L, v1); | 102 | case LUA_OPUNM: return luai_numunm(L, v1); |
103 | case LUA_OPMOD: { | ||
104 | lua_Number m; | ||
105 | luai_nummod(L, v1, v2, m); | ||
106 | return m; | ||
107 | } | ||
104 | default: lua_assert(0); return 0; | 108 | default: lua_assert(0); return 0; |
105 | } | 109 | } |
106 | } | 110 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.193 2014/03/21 14:27:16 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.194 2014/04/03 14:18:02 roberto Exp $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -497,7 +497,8 @@ | |||
497 | /* the following operations need the math library */ | 497 | /* the following operations need the math library */ |
498 | #if defined(lobject_c) || defined(lvm_c) | 498 | #if defined(lobject_c) || defined(lvm_c) |
499 | #include <math.h> | 499 | #include <math.h> |
500 | #define luai_nummod(L,a,b) ((void)L, (a) - l_floor((a)/(b))*(b)) | 500 | #define luai_nummod(L,a,b,m) \ |
501 | { (m) = l_mathop(fmod)(a,b); if ((m) != 0 && (a)*(b) < 0) (m) += (b); } | ||
501 | #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) | 502 | #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) |
502 | #endif | 503 | #endif |
503 | 504 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.193 2014/04/02 16:54:20 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.194 2014/04/08 14:28:04 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -755,7 +755,9 @@ void luaV_execute (lua_State *L) { | |||
755 | setivalue(ra, luaV_mod(L, ib, ic)); | 755 | setivalue(ra, luaV_mod(L, ib, ic)); |
756 | } | 756 | } |
757 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { | 757 | else if (tonumber(rb, &nb) && tonumber(rc, &nc)) { |
758 | setnvalue(ra, luai_nummod(L, nb, nc)); | 758 | lua_Number m; |
759 | luai_nummod(L, nb, nc, m); | ||
760 | setnvalue(ra, m); | ||
759 | } | 761 | } |
760 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } | 762 | else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); } |
761 | ) | 763 | ) |