lua-users home
lua-l archive

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

The choice of sign seems to vary pretty widely, so IMHO portable code should not depend on it. Since Lua has implementations in many languages and aims to be fast it would be an unreasonable tradeoff to make the underlying operation conform to the original C implementation. Modulo is already among the slower operations, so the extra overhead is not necessarily worth it.

On Tue, Jan 24, 2017 at 11:21 PM, Milo Christiansen <> wrote:
In Lua 5.3 "-3%5 == 2", according to my programmers calculator and several other programing languages I tried this _expression_ in, the real result is -3.

On the other hand "5%-3 == 2", so maybe the result is correct, and the bug is simply reversed operands if one is negative?

I discovered this because I am adding tests (based on the official Lua tests) to my Go Lua VM, and one of the tests failed because the incorrect result is coded into the test.