[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [5.3] Converting a floating point number to integer.
- From: Karel Tuma <kat@...>
- Date: Mon, 17 Nov 2014 02:33:56 +0100
Excerpts from Liam Devine's message of 2014-11-16 13:09:38 UTC:
> What is the current recommended method of converting a float to int?
> Should it be to check if it is greater than zero and floor else use
> ceiling and then finally use one of the above conversion methods?
>
> If this behaviour is to stay, would it be time to have a cast operator
> int() ?
I'm not particularly fond of Lua 5.3 overzealous checking of fractions
and ranges when doing float->int integers conversions either.
One quick hack to perform "just convert float to int no matter what, and
to the hell with the consequences, like C would do" is:
int = string.format("%.0f", float))|0
I wish there was some built-in support for this (say, math.to_unsafe_int() or
something).