• 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, 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.
```
```
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 sense that once you define one of them, you've implicitly defined the other one and therefore you should provide both, in the same sense that if you were
```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 people
```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.

```