[ create a new paste ] login | about

Link: http://codepad.org/XmWHCBXg    [ raw code | output | fork ]

Lua, pasted on Jul 31:
1
2
3
4
5
6
7
8
9
10
11
12
13
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))


Output:
1
rint(0.50001) = 0


Create a new paste based on this one


Comments: