lua-users home
lua-l archive

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


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: pgp_XpNXQOFgb.pgp
Description: PGP signature