[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: [Bug] math.mod behaves differently than the modulus operator.
- From: "Grellier, Thierry" <t-grellier@...>
- Date: Mon, 28 Jan 2008 10:09:16 +0100
Well, I find it weak defense to say that manual doesn't claim
consistency (one may then consider this a manual issue). Because
consistency in that case, is probably what we could normally expect from
a language. Then it is surprising that Lua doesn't share code for % and
math.mod and not very shocking to consider this a bug (or probably non
wish able inconsistency for sensitive hears), especially when Lua
enforces the rule one way and only one to do things especially to limit
inconsistency risks and reduce code size.
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Daniel
Stephens
Sent: Sunday, January 27, 2008 12:40 AM
To: Lua list
Subject: Re: [Bug] math.mod behaves differently than the modulus
operator.
Tom Barta wrote:
> On Jan 26, 2008 4:29 PM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> wrote:
>
>> Please don't cry BUG when you see something you don't expect.
>>
>
> Out of curiosity, is there any explicit reason for math.mod() behaving
> differently than the modulus operator (%)? It seems counterintuitive
> that they behave differently (despite the lack of a formal guarantee
> by the manual), but maybe I'm overlooking some case where the
> distinction is worthwhile.
>
They have different behaviors for values where the sign of the value is
different from the divisor, each can be more or less useful in different
situations depending on your needs.
For example, Lua's choice of implementation guarantees that a % b == (a
+ N * b) % b for all integer N, whereas math.mod does not.