[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: integer lua
- From: David Given <dg@...>
- Date: Tue, 23 Aug 2005 21:05:43 +0100
On Tuesday 23 August 2005 20:50, Walter Cruz wrote:
[...]
> well, after I send the e-mail, I thinked that I can use the string
> library and just strip the chars after the dot, right ?
That'll work, but it'll be quite slow. It'll be equivalent to the C function
trunc(), which Lua doesn't seem to have.
math.floor() rounds towards -Inf; 1.2 => 1 and -1.2 => -2.
math.ceil() rounds towards +Inf; 1.2 => 2 and -1.2 => -1.
trunc() rounds towards 0. 1.2 => 1 and -1.2 => -1.
I don't believe there's an easy way of doing 'ordinary' rounding; that is, 1.2
-> 1, 1.8 -> 2. In C, this is rint().
(Is the absence of math.trunc() and math.rint() intentional, or just an
oversight?)
--
"Curses! Foiled by the chilled dairy treats of righteousness!" --- Earthworm
Jim (evil)
Attachment:
pgpJCalYem60A.pgp
Description: PGP signature