lua-users home
lua-l archive

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


As the local mouthpiece of the Errorists, I must suggest questions are better than silent bugs.

On Nov 16, 2014 4:13 PM, "Tim Hill" <drtimhill@gmail.com> wrote:

> On Nov 16, 2014, at 11:46 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>
> 2014-11-16 21:26 GMT+02:00 Ico <lua@zevv.nl>:
>> * On 2014-11-16 20:01:03 +0100, Dirk Laurie wrote:
>>
>>> The user must decide what is correct for his application: floor, ceil,
>>> closest (coded e.g. as floor(x+0.5)), truncate (as you suggest)
>>
>> What would be the idiomatic way to truncate a float to int in Lua 5.3?
>
> function truncate(x)
>   return x<0 and math.ceil(x) or math.floor(x)
> end
>

Looking into my (foggy) crystal ball, I predict that questions about converting float to int will be THE most asked when 5.3 ships.

—Tim