lua-users home
lua-l archive

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


On 2012-11-14 12:21 PM, "Petri Häkkinen" <petrih3@gmail.com> wrote:
>
> On 14.11.2012, at 8.54, Petri Häkkinen wrote:
>
> >> This definition screams for the symbol `/%`.
> >>
> >>> q, r = 42 /% 10  --> 4,2
> >>
> >> Dirk
> >>
> >
> > Indeed. But /% looks like some sort of escape sequence, I would perhaps go with %%.
>
> Oh, I think I got Dirk's idea the wrong way. I thought you were suggesting /% to be the modulo operator.
>
> What I meant was: I would prefer separate operators // and %% (integer division and modulo) over /%. The reason: there are no combined operators +-, */, <> etc. either…. you get the idea  ;-)
>
> On 14.11.2012, at 15.37, Roberto Ierusalimschy wrote:
>
> >> May I ask what is the opinion of Roberto regarding these new operators?
> >
> > I think we always stated that the main problem with bitwise operators
> > in Lua was that they do not have a "natural" interpretation over Lua
> > numbers. If Lua gets integers, this problem is gone.
>
> That's what I thought. Thanks!
>
> Petri
>
>

It's maybe worth noting though that a lot of FPUs can give both x / y and x % y in a single instruction. Having Lua mirror this by having two values returned from % seems like it'd make possible optimization easier.

But I wonder if there's existing code that might break, such as f(x % y) now passing an extra argument?