lua-users home
lua-l archive

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


On Sat, Jul 30, 2016 at 4:02 PM, Duane Leslie <parakleta@darkreality.org> wrote:
A fixed version then:

```lua
function rint(x)
    if x ~= x or x < -0x1p+52 or x > 0x1p+52 then
        -- Already an Integer, or NaN, or Inf
    elseif x < 0 then
        x = ((x - 0x1p+52) + 0x1p+52)
    else
        x = ((x + 0x1p+52) - 0x1p+52)
    end
    return math.floor(x)
end
```

One more problem:

> rint(0.50001)
0