[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modulo operator produces incorrect results with negative operand(s).
- From: Sean Conner <sean@...>
- Date: Wed, 8 Feb 2017 21:24:17 -0500
It was thus said that the Great Martin once stated:
> Thank you for clarifying, guys!
>
> Now I see that requirement of non-negative remainder is quite practical
> and well-binded with mathematical rings of natural numbers.
>
> Sadly (as I understand from similar discussions before) Lua
> implementation is heavily linked with ANSI C and Roberto generally not
> willing to introduce changes in logic that is different from ANSI C.
>
> Although I consider "%" and math.mod() behavior change worth it.
Further fuel for the fire. I did three different versions of mod---one in
assembly (x86 32bit), C (x86 32bit) and Lua 5.3 (x86 32bit). The results:
[spc]lucy:/tmp>./mod 7 3
A: 2 1
C: 2 1
L: 2 1
[spc]lucy:/tmp>./mod -7 3
A: -2 -1
C: -2 -1
L: -3 2
[spc]lucy:/tmp>./mod 7 -3
A: -2 1
C: -2 1
L: -3 -2
[spc]lucy:/tmp>./mod -7 -3
A: 2 -1
C: 2 -1
L: 2 -1
[spc]lucy:/tmp>
-spc (Make of that what you will)