[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Language Syntax
- From: Choonster TheMage <choonster.2010@...>
- Date: Tue, 24 Jun 2014 15:43:32 +1000
On 24 Jun 2014 13:52, "Lucas" <cad.lua@lucasjr.nospammail.net> wrote:
>
> Ok, my intention was to write such a function
>
> function modulus(n, d) return n - (q = math.floor(n/d)) * d, q; end
>
> is there any means to write it down just as simple?
>
> r, q = modulus(10, 3)
>
Sticking with your existing technique:
function modulus(n, d)
local q = math.floor(n/d)
return n - q * d, q
end
Using the modulus operator (I'm pretty sure this is correct):
function modulus(n, d)
return n % d, math.floor(n/d)
end
Regards,
Choonster