lua-users home
lua-l archive

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


Why not \ instead of // ?

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Rici Lake
Sent: Friday, September 22, 2006 1:53 AM
To: Lua list
Subject: Re: boolean operators


On 21-Sep-06, at 5:01 PM, David Jones wrote:

>
> Le 21 Sep 2006 à 21:28, Rici Lake a écrit :
>
>>
>> Regardless of bitwise operators, I would vote strongly in favour
>> of an integer divide operator, to go along with 5.1's remainder (%)
>> operator. At the risk of alienating C++ programmers, I'd suggest
>> that integer divide be spelled "//". It's precise definition
>> would be:  a // b ==>  (a - a%b) / b
>
> Lispers would ask for floor, ceiling, truncate, and round as well.  
> Funny how no-one ever wants round-away-from 0, could be called 
> "inflate" perhaps?
>

In Lua, % is defined as "the remainder of the division that rounds the 
quotient towards minus infinity".


Consequently:

floor: a // 1
ceiling: -(a // -1)
round: (a + .5) // 1

(I don't have a good one for truncate, without using abs and sign).

Still, I think // is pretty generally useful.