From 06e08c6d05b1346df935634be395f4d86035e3ea Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 9 Jul 2018 12:41:24 -0300 Subject: Fixed bug in OP_IDIVI Opocode was using 'luai_numdiv' (float division) instead of 'luai_numidiv' (integer division). --- lvm.c | 4 ++-- testes/math.lua | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lvm.c b/lvm.c index 9e8bec0c..4e4ef270 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.358 2018/06/15 14:14:20 roberto Exp roberto $ +** $Id: lvm.c,v 2.359 2018/06/18 17:58:21 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -1182,7 +1182,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } else if (tonumberns(rb, nb)) { lua_Number nc = cast_num(ic); - setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); + setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); } else 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 @@ --- $Id: math.lua,v 1.86 2018/05/09 14:55:52 roberto Exp $ +-- $Id: math.lua,v 1.86 2018/05/09 14:55:52 roberto Exp roberto $ -- See Copyright Notice in file all.lua print("testing numbers and math lib") @@ -139,6 +139,17 @@ assert(-1 // 0.0 == -1/0) assert(eqT(3.5 // 1.5, 2.0)) assert(eqT(3.5 // -1.5, -3.0)) +do -- tests for different kinds of opcodes + local x, y + x = 1; assert(x // 0.0 == 1/0) + x = 1.0; assert(x // 0 == 1/0) + x = 3.5; assert(eqT(x // 1, 3.0)) + assert(eqT(x // -1, -4.0)) + + x = 3.5; y = 1.5; assert(eqT(x // y, 2.0)) + x = 3.5; y = -1.5; assert(eqT(x // y, -3.0)) +end + assert(maxint // maxint == 1) assert(maxint // 1 == maxint) assert((maxint - 1) // maxint == 0) -- cgit v1.2.3-55-g6feb