Package: purescript-lua-integers
File: src/Data/Int.lua
Function: pow
Class: semantics Severity: medium
Upstream JS is Math.pow(x,y) | 0 — it both truncates the result toward zero and wraps it to Int32. The Lua omits the truncation: math.pow(x, y) returns a float and is not floored/truncated. For negative exponents the result is a fraction, so pow 2 (-1) is 0.5 in Lua but must be 0 (Test/Data/Int.purs lines 180-183: pow 2 (-1) == 0, pow 2 (-2) == 0, pow (-2) (-2) == 0). Even for non-negative exponents the result is a float (8.0 not 8) and large results are not wrapped to Int32.
Current (Lua):
pow = (function(x) return function(y) return math.pow(x, y) end end)
Expected: Integer result truncated toward zero (and ideally Int32-wrapped): pow 2 (-1) == 0, pow 2 (-2) == 0, pow (-2) (-2) == 0, pow 2 2 == 4.
Proposed fix:
pow = (function(x) return function(y)
local r = math.modf(math.pow(x, y)) -- truncate toward zero like JS `| 0`
return r
end end)
Found by the FFI audit; reproduced under Lua 5.1.
Package: purescript-lua-integers
File:
src/Data/Int.luaFunction:
powClass: semantics Severity: medium
Upstream JS is
Math.pow(x,y) | 0— it both truncates the result toward zero and wraps it to Int32. The Lua omits the truncation:math.pow(x, y)returns a float and is not floored/truncated. For negative exponents the result is a fraction, sopow 2 (-1)is 0.5 in Lua but must be 0 (Test/Data/Int.purs lines 180-183: pow 2 (-1) == 0, pow 2 (-2) == 0, pow (-2) (-2) == 0). Even for non-negative exponents the result is a float (8.0 not 8) and large results are not wrapped to Int32.Current (Lua):
Expected: Integer result truncated toward zero (and ideally Int32-wrapped): pow 2 (-1) == 0, pow 2 (-2) == 0, pow (-2) (-2) == 0, pow 2 2 == 4.
Proposed fix:
Found by the FFI audit; reproduced under Lua 5.1.