function rint(x)
local two52 = 4503599627370496.0
if x ~= x or x < -two52 or x > two52 then
-- Already an Integer, or NaN, or Inf
elseif x < 0 then
x = ((x - two52) + two52)
else
x = ((x + two52) - two52)
end
return math.floor(x)
end
print("rint(0.50001) = "..rint(0.50001))