lua-users home
lua-l archive

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



The way % is defined, it's rather useful for controlling reported accuracy of numbers, not only for integers.

I think Roberto et.al. did a jolly good job in the way that operator came in; it's probably just veeeery underutilized at the moment. :)

-asko

(maybe because it's not emphasized in the online documentation; I think I've seen discussion on the use of % somewhere, maybe PIL book, then?

Ref.manual simply states this: "Modulo is defined as
     a % b == a - math.floor(a/b)*b
That is, it is the remainder of a division that rounds the quotient towards minus infinity."

In practise, 123.45 % 0.1 = 0.05 (or... so it SHOULD be :)

print( 123.45 % 0.1 )
0.049999999999996

Now, when can we get the BCD number implementation?  :P
)



On Wed, 27 Sep 2006 06:16:31 -0400
 Glenn Maynard <glenn@zewt.org> wrote:
On Thu, Sep 21, 2006 at 06:53:26PM -0500, Rici Lake wrote:
In Lua, % is defined as "the remainder of the division that rounds the quotient towards minus infinity".

At the cost of being repetitive, is there a reason for wanting this, other than performance (discussed elsewhere)? It just seems like there's a whole lot of calls for more and more operators in Lua these days--on the tail of someone asking for a table append operator comes the bitwise operator thread, and then this. With an operator for every operation that "inline" would be useful for in C, there will be a lot of operators.

--
Glenn Maynard