Why do some compilers violate the defined language standard?
I don't understand, in ISO/IEC 10206:1990 Extended Pascal standard on 188.8.131.52 Arithmetic operators section, Page 86.
It says that,
A term of the form i mod j shall be an error if j is zero or negative ; otherwise, the value of i mod j shall be that value of (i-(k*j)) for integral k such that 0 < = i mod j < j.
But, when I try in free pascal compiler 3.0,
writeln(-5 mod 3);
It produces a negative number "-2" instead of "1", and
writeln(5 mod -3);
Should be error according to the standard,
but what I found is not.
For example, if there is a question
"In C++, why does the -5 % 3 produce -2 instead of 1, isn't it modulo operator?"
I should answer
That's because in C++14 standard on Page 124, 5.6 Multiplicative operators, no. 4
It says that "(a/b)*b + a%b is equal to a"
Therefore, it is not a modulo operator, it is a remainder operator
But If there is a question,
"In Pascal, why does the -5 mod 3 produce -2 instead of 1, isn't it modulo operator?"
Should the answer be like this?
In general, it depends on the compilers that you are using, because according to the ISO/IEC 10206:1990 Extended Pascal standard, it should be 1, while on a modern compilers like fpc or gpc,
it produces -2
What would be the most appropriate answer to the modulo operator question above?