lua-users home
lua-l archive

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

On Wednesday, October 03, 2007 Miles Bader wrote: 

> So it seems like David's almost certainly right:  since they couldn't
> use the underlying % operator, they just used the "equivalent formula",
> "a - b * floor (a / b)", and that gives a slightly different result than
> the C integer operator on typical hardware.

Yes, the point is that in programming languages we want to have
matched pairs of "quotient" and "remainder" operations such that

q = quotient(a,b)
r = remainder(a,b)
a = b * q + r

Lua's % and math.floor make such a pair.

An excellent comparison of some choices in this space is
which is summarized at


Doug Currie
Londonderry, NH, USA