|
Le 22 Sep 2006 à 00:53, Rici Lake a écrit :
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) / bLispers 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".
Yes I know, I thank the Lua designers every time I use % that they defined it to Do The Right Thing. Unlike C.
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.
Yup so do I. Btw in Lisp those functions can take 2 arguments and do divisions.
And round does IEEE style rounding. Not the easy-to-implement biased style.
But as you point out, you can define integer divide, floor as Lisp calls it, yourself.
drj