lua-users home
lua-l archive

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

Well then I would maybe prefer that this is clearly stated in the manual
that % and math.fmod differ.

And I won't dig in the mail list to see why it was so important to
support 2 definitions instead of choosing 1. Guess I'm still too used to
have both integer and float numbers in programming languages. 

And well I can always do math.fmod = function (a,b) return a%b end

-----Original Message-----
[] On Behalf Of Mike Pall
Sent: Monday, January 28, 2008 1:20 PM
To: Lua list
Subject: Re: [Bug] math.mod behaves differently than the modulus

Grellier, Thierry wrote:
> Well, I find it weak defense to say that manual doesn't claim
> consistency (one may then consider this a manual issue).

Umm, I guess you've not been on the list back then ... math.mod
was there before %. It's also clearly marked as a compatibility
function (renamed to math.fmod). Which btw is the main reason why
the behaviour is different and why two variants are required.

The manual is pretty consistent with the implementation:

"[The] Modulo [operator] is defined as a % b == a - math.floor(a/b)*b
 That is, it is the remainder of a division that rounds the quotient
 towards minus infinity."

"math.fmod (x, y) -- Returns the remainder of the division of x by y."