lua-users home
lua-l archive

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


I'm curious why during Lua's development it was decided that the
modulus operator be implemented

in Lua:

-7 % 5 = 3

where in C:

-7 % 5 = -2

All mathematicians I've spoken to agree that the modulus is defined by division:

a = b * q + r

such that q is an integer and r is a natural number.

Naturally -2 is part of the congruence class 3 bar (mod 5) (can't make
the symbol in plain text).

I would say Lua has done it "correctly", but I'm afraid some
mathematicians would disagree and say:

0 <= abs(r) < abs(b)

So, was there a reason why? Personally I'm pretty happy it was defined
the way it was.

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant