lua-users home
lua-l archive

Re: Language Syntax

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


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

AltStyle によって変換されたページ (->オリジナル) /