[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: boolean operators
- From: Rici Lake <lua@...>
- Date: Wed, 27 Sep 2006 10:52:35 -0500
On 27-Sep-06, at 5:16 AM, Glenn Maynard 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,
than performance (discussed elsewhere)? It just seems like there's a
lot of calls for more and more operators in Lua these days--on the
someone asking for a table append operator comes the bitwise operator
thread, and then this. With an operator for every operation that
would be useful for in C, there will be a lot of operators.
Clarity of expression, really. I personally could live without bitwise
operators, or table append syntax.
Now, it's true that you can define a // b as math.floor(a / b), but then
you could define a % b as a - b * math.floor(a / b), but I'd argue that
in both cases, the operator is a clearer statement of intent.
To my mind, remainder and integer-division are complementary in the
that once you define one of them, you've implicitly defined the other
and therefore you should provide both, in the same sense that if you
implementing bitstring operators you wouldn't need both 'band' and 'bor'
since you could define 'bor' as 'bnot (bnot a band bnot b)' but most
would find that excessively minimalistic.
Similarly, if I'm overriding arithmetic operators for some numeric type
(say bignums or decnums), the efficiency difference between a native
integer-division implementation and the non-native one ((a - a % b) / b)
would be non-trivial.