[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [5.3] Converting a floating point number to integer.
- From: "Liam Devine" <liamdevine@...>
- Date: Sun, 16 Nov 2014 23:04:00 -0000
On 16/11/14 19:46, Dirk Laurie 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
>
Having looked at it more closely I would probably use math.modf
--
Liam
Attachment:
signature.asc
Description: OpenPGP digital signature