lua-users home
lua-l archive

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


but that would calculate the same division twice, is there any means to
get the % operator return both the reminder AND the quotient?

r, q = 10 %% 3

or the like? my processing is getting slow with a mobile processor

On Tue, Jun 24, 2014, at 02:43, Choonster TheMage wrote:
> 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
>