I noticed that A mod N (or mod(A, N)) operation in MathJS doesn't return expected values ("expected" in terms of modular arithmetic) for negative values of A. For example, -5 mod 3 returns -2 while the correct result should be 1 (example on wolframalpha).
In addition, mod also works for negative values of N while I think modulo operation is only defined for N > 1.
Here is an example of what MathJS returns (you can see it on clcalc that uses MathJS):
5 mod 3 = 2
-5 mod 3 = -2
5 mod -3 = 2
However, while some programming languages like JS, or C/C++ (example) produce the same result
(although, my understanding is that for C/C++ the result in case of negative A is implementation defined), some others, like Python, give different answer (example).
The text was updated successfully, but these errors were encountered: