lua-users home
lua-l archive

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

On Wed, Sep 27, 2006 at 10:50:27PM -0500, Rici Lake wrote:
> >This is why % and // seem out of place to me; integers are not a
> >fundamental type in Lua, only numbers are.  (Granted, % is defined
> >for floating point numbers, but I have no idea what use it has and
> >its primary use seems intended to be integers.)
> It is sometimes useful to do integer arithemetic; a useful subset of 
> Lua numbers are integers. A number of interesting algorithms involve 
> integer arithmetic.

Integers are bit masks; bit masks are as much fundamental types in
Lua as integers, by this logic.  Also, % is floating point modulus;
looking at a particular subset of its uses (integer remainder) and
wanting a paired operator with that seems like rationalizing a sqrt()
operator because a subset of multiplication is squaring.

> But as you say, % (and //) are well-defined for non-integers, and they 
> do have uses even if they haven't been useful for you. (I have $1.38 in 
> my pocket, and apples cost $0.16 each. How many apples can I buy?)

floor(1.38/0.16), or 1.38/0.16 if I have a knife.  I don't need a new
operator to do that.

Glenn Maynard