[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Modulo**
**From**: Doug Currie <doug.currie@...>
**Date**: Wed, 3 Oct 2007 21:51:39 -0400

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
if
q = quotient(a,b)
r = remainder(a,b)
then
a = b * q + r
Lua's % and math.floor make such a pair.
An excellent comparison of some choices in this space is
http://portal.acm.org/citation.cfm?id=128862&coll=portal&dl=ACM
which is summarized at
http://en.wikipedia.org/wiki/Modulo_operation
e
--
Doug Currie
Londonderry, NH, USA