News for hackers. Stuff that matters.
Re:A Reply to “Let’s stop copying C” by mjevans on Saturday January 25, 2020 @09:37PM (#22150033)
I think you are probably correct. Lets try a set of simple cases.

    ( 4  % 3) == 1
    ( 4 %% 3) == 1
Are these two correct answers?

    (-4  % 3) == -2 ??
    (-4 %% 3) == 1 ??
Lets assume I got that correct and plug in some numbers.

     a %% b == (( a % b) +  **b** ) % b
    -4 %% 3 == ((-4 % 3) + 3 ) % 3
    -4 %% 3 == (-2 + 3) % 3
    -4 %% 3 == 1
However I think it would be clearer for maintenance if the extra operator wasn't used and instead some 'math.absolute()' function were used.

PS: Hopefully those are short enough to not die on mobile

Re:A Reply to “Let’s stop copying C” by Vassvik on Sunday January 26, 2020 @05:29AM (#22151405)
It's definitely a typo.

Conceptually I prefer looking at them as

    a % b  = a - trunc(a / b) * b
    a %% b = a - floor(a / b) * b
 
The latter is even used as % in languages such as Python, which further compounds any syntactical confusion. :D
Re:A Reply to “Let’s stop copying C” by klyrs on Saturday January 25, 2020 @11:30PM (#22150389)
4%3 is 1, so -4%3=-1=3-1=2 (mod 3).

I disagree about maintenance: use the right formula and do careful unit testing. Abs isn't a great help here either.