Package: purescript-lua-numbers
File: src/Data/Number.lua
Function: max
Class: semantics Severity: medium
PureScript docstring (Number.purs lines 196-197) states this version returns NaN if EITHER argument is NaN, matching JS Math.max. Lua math.max folds with the > operator, and nan > x is false, so it keeps whichever non-NaN argument it visited: max(1)(nan) returns 1 (confirmed under Lua 5.1) rather than NaN. NaN propagation is therefore order-dependent (max(nan)(1) does yield nan, max(1)(nan) does not).
Current (Lua):
max = (function(n1) return function(n2) return math.max(n1, n2) end end)
Expected: max NaN x = NaN and max x NaN = NaN for any x, like JS Math.max.
Proposed fix:
Add an explicit NaN guard: `function(n1) return function(n2) if n1 ~= n1 or n2 ~= n2 then return 0/0 else return math.max(n1, n2) end end end`.
Found by the FFI audit; reproduced under Lua 5.1.
Package: purescript-lua-numbers
File:
src/Data/Number.luaFunction:
maxClass: semantics Severity: medium
PureScript docstring (Number.purs lines 196-197) states this version returns NaN if EITHER argument is NaN, matching JS Math.max. Lua math.max folds with the > operator, and
nan > xis false, so it keeps whichever non-NaN argument it visited: max(1)(nan) returns 1 (confirmed under Lua 5.1) rather than NaN. NaN propagation is therefore order-dependent (max(nan)(1) does yield nan, max(1)(nan) does not).Current (Lua):
Expected: max NaN x = NaN and max x NaN = NaN for any x, like JS Math.max.
Proposed fix:
Found by the FFI audit; reproduced under Lua 5.1.