[Tarantool-patches] [PATCH v2 luajit 18/30] test: replace math.mod to math.fmod for Lua tests

Sergey Kaplun skaplun at tarantool.org
Fri Mar 26 10:43:01 MSK 2021


In Lua 5.1 math.mod() is renamed to math.fmod() if build Lua 5.1 without
flag `-DLUA_COMPAT_MOD`.
LuaJIT has math.fmod() instead old-style math.mod() built-in.

This patch replaces usage of math.mod with new-style math.fmod
in the following files:
* closure.lua
* constructs.lua
* math.lua
* nextvar.lua

Closes tarantool/tarantool#5711
Part of tarantool/tarantool#5845
Part of tarantool/tarantool#4473
---
 test/PUC-Lua-5.1-tests/closure.lua    | 3 ++-
 test/PUC-Lua-5.1-tests/constructs.lua | 6 ++++--
 test/PUC-Lua-5.1-tests/math.lua       | 3 ++-
 test/PUC-Lua-5.1-tests/nextvar.lua    | 3 ++-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/test/PUC-Lua-5.1-tests/closure.lua b/test/PUC-Lua-5.1-tests/closure.lua
index 27ca0ad..7f56ab8 100644
--- a/test/PUC-Lua-5.1-tests/closure.lua
+++ b/test/PUC-Lua-5.1-tests/closure.lua
@@ -254,7 +254,8 @@ function filter (p, g)
     while 1 do
       local n = g()
       if n == nil then return end
-      if math.mod(n, p) ~= 0 then coroutine.yield(n) end
+      -- LuaJIT: use `math.fmod()` instead old-style `math.mod()`.
+      if math.fmod(n, p) ~= 0 then coroutine.yield(n) end
     end
   end)
 end
diff --git a/test/PUC-Lua-5.1-tests/constructs.lua b/test/PUC-Lua-5.1-tests/constructs.lua
index 5fb3798..18d1789 100644
--- a/test/PUC-Lua-5.1-tests/constructs.lua
+++ b/test/PUC-Lua-5.1-tests/constructs.lua
@@ -202,7 +202,8 @@ function ID(x) return x end
 
 function f(t, i)
   local b = t.n
-  local res = math.mod(math.floor(i/c), b)+1
+  -- LuaJIT: use `math.fmod()` instead old-style `math.mod()`.
+  local res = math.fmod(math.floor(i/c), b)+1
   c = c*b
   return t[res]
 end
@@ -233,7 +234,8 @@ repeat
   ]], s1, s, s1, s, s1, s, s1, s, s)
   assert(loadstring(s))()
   assert(X and not NX and not WX1 == K and not WX2 == K)
-  if math.mod(i,4000) == 0 then print('+') end
+  -- LuaJIT: use `math.fmod()` instead old-style `math.mod()`.
+  if math.fmod(i,4000) == 0 then print('+') end
   i = i+1
 until i==c
 
diff --git a/test/PUC-Lua-5.1-tests/math.lua b/test/PUC-Lua-5.1-tests/math.lua
index 5076f38..8f0526f 100644
--- a/test/PUC-Lua-5.1-tests/math.lua
+++ b/test/PUC-Lua-5.1-tests/math.lua
@@ -100,7 +100,8 @@ assert(math.abs(-10) == 10)
 assert(eq(math.atan2(1,0), math.pi/2))
 assert(math.ceil(4.5) == 5.0)
 assert(math.floor(4.5) == 4.0)
-assert(math.mod(10,3) == 1)
+-- LuaJIT: use `math.fmod()` instead old-style `math.mod()`.
+assert(math.fmod(10,3) == 1)
 assert(eq(math.sqrt(10)^2, 10))
 assert(eq(math.log10(2), math.log(2)/math.log(10)))
 assert(eq(math.exp(0), 1))
diff --git a/test/PUC-Lua-5.1-tests/nextvar.lua b/test/PUC-Lua-5.1-tests/nextvar.lua
index 7ceaa75..81159dc 100644
--- a/test/PUC-Lua-5.1-tests/nextvar.lua
+++ b/test/PUC-Lua-5.1-tests/nextvar.lua
@@ -201,7 +201,8 @@ print('+')
 
 a = {}
 for i=0,10000 do
-  if math.mod(i,10) ~= 0 then
+  -- LuaJIT: use `math.fmod()` instead old-style `math.mod()`.
+  if math.fmod(i,10) ~= 0 then
     a['x'..i] = i
   end
 end
-- 
2.31.0



More information about the Tarantool-patches mailing list