lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!

The functions "math.max" and "math.min" do not give mathematically correct result in Lua 5.3:
Lua 5.2: math.max('11','2') == 11  -- mathematically correct
Lua 5.3: math.max('11','2') == '2' -- mathematically incorrect
The semantics of these functions have been changed considerably.

This is an example of how using old name "math.min" with new function semantics leads to well-hidden bug in old code:

----------------
local function check_limits(value, ...)
   local eps = 0.000001
   return math.abs(value) < math.min(...) + eps
end

print(check_limits('3.14', '2', '11'))
   --> false on Lua 5.2
   --> true on Lua 5.3
----------------

IMO, functions "math.max" and "math.min" should be removed from "math" library as they do not have anything common with mathematics anymore.
As "min" and "max" are applicable now for any comparable objects in Lua, they are better suited for global namespace.

-- Egor