lua-users home
lua-l archive

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


Thursday, May 19, 2005, 6:52:16 AM, Gavin wrote:

>[...]

> 1. "For all integers x and y, y nonzero implies there exist
> unique integers q and r such that x = qy + r and 0 <= r < abs(y)."

> 2. "For all integers x and y, y nonzero implies there exist
> unique integers q and r such that x = qy + r, sgn(r) = sgn(x) and
> abs(r) < abs(y)."

> So for (x,y) = (-3,2) the first formulation of the remainder
> theorem gives (q,r) = (-2,1) and the second gives (q,r) = (-1,-1).

Gavin gives a nice succinct definition of two of three good ways to
define div & mod (or quo and rem). For the third way, and a full
treatment of the subject, see: http://doi.acm.org/10.1145/128861.128862

e