[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why is there no 'math.round'?
- From: Paul Smith <paullocal@...>
- Date: Wed, 23 Apr 2008 14:34:38 +0100
Bogdan Marinescu wrote:
Of course. But then again, Lua does provide a math library. So a
'round' function would fit quite nicely in there :)
Lua DOES have a 'round' function - 2 in fact .... math.floor() rounds
down for you, and math.ceil() rounds up for you. :)
If that's not what you want, you can write one to do what you want in a
few seconds. Making a 'math.round' which rounds to the nearest integer
is a couple of lines of code. You can always just add that to your
standard set of functions you use. If you can't do write a 'math.round'
function, then you probably couldn't use Lua much at all anyway.
Lua is minimalist. math.round() can trivially be added to do what you
want using the existing functions. The maths library is generally just
stuff which is harder to do - eg making a math.floor() would actually be
quite hard, as would math.cos, math.log etc.