diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-09 12:41:24 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-09 12:41:24 -0300 |
commit | 06e08c6d05b1346df935634be395f4d86035e3ea (patch) | |
tree | 81f7fee528638347fd30aa6fe6df30a55819900d | |
parent | 7c519dfbd0c68b952f0849e01deaa3750e1f8153 (diff) | |
download | lua-06e08c6d05b1346df935634be395f4d86035e3ea.tar.gz lua-06e08c6d05b1346df935634be395f4d86035e3ea.tar.bz2 lua-06e08c6d05b1346df935634be395f4d86035e3ea.zip |
Fixed bug in OP_IDIVI
Opocode was using 'luai_numdiv' (float division) instead of
'luai_numidiv' (integer division).
-rw-r--r-- | lvm.c | 4 | ||||
-rw-r--r-- | testes/math.lua | 13 |
2 files changed, 14 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.358 2018/06/15 14:14:20 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.359 2018/06/18 17:58:21 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 | */ |
@@ -1182,7 +1182,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1182 | } | 1182 | } |
1183 | else if (tonumberns(rb, nb)) { | 1183 | else if (tonumberns(rb, nb)) { |
1184 | lua_Number nc = cast_num(ic); | 1184 | lua_Number nc = cast_num(ic); |
1185 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); | 1185 | setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); |
1186 | } | 1186 | } |
1187 | else | 1187 | else |
1188 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV)); | 1188 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV)); |
diff --git a/testes/math.lua b/testes/math.lua index 66998460..e5c9d8ec 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | -- $Id: math.lua,v 1.86 2018/05/09 14:55:52 roberto Exp $ | 1 | -- $Id: math.lua,v 1.86 2018/05/09 14:55:52 roberto Exp roberto $ |
2 | -- See Copyright Notice in file all.lua | 2 | -- See Copyright Notice in file all.lua |
3 | 3 | ||
4 | print("testing numbers and math lib") | 4 | print("testing numbers and math lib") |
@@ -139,6 +139,17 @@ assert(-1 // 0.0 == -1/0) | |||
139 | assert(eqT(3.5 // 1.5, 2.0)) | 139 | assert(eqT(3.5 // 1.5, 2.0)) |
140 | assert(eqT(3.5 // -1.5, -3.0)) | 140 | assert(eqT(3.5 // -1.5, -3.0)) |
141 | 141 | ||
142 | do -- tests for different kinds of opcodes | ||
143 | local x, y | ||
144 | x = 1; assert(x // 0.0 == 1/0) | ||
145 | x = 1.0; assert(x // 0 == 1/0) | ||
146 | x = 3.5; assert(eqT(x // 1, 3.0)) | ||
147 | assert(eqT(x // -1, -4.0)) | ||
148 | |||
149 | x = 3.5; y = 1.5; assert(eqT(x // y, 2.0)) | ||
150 | x = 3.5; y = -1.5; assert(eqT(x // y, -3.0)) | ||
151 | end | ||
152 | |||
142 | assert(maxint // maxint == 1) | 153 | assert(maxint // maxint == 1) |
143 | assert(maxint // 1 == maxint) | 154 | assert(maxint // 1 == maxint) |
144 | assert((maxint - 1) // maxint == 0) | 155 | assert((maxint - 1) // maxint == 0) |