Adriaan van Os wrote:
... snip ...
I might be interesting to note that not all Pascal compilers follow the ISO 7185 Pascal standard for the mod operator. The standard states:
"Evaluation of a term of the form x mod y is an error if y is less than or equal to zero; otherwise there is an integer k such that x mod y satisfies the following relation:
0 <= x mod y = x - k * y < y."
But on page 6-5 of the Delphi 3 Object Pascal Language Guide, we read:
"The mod operator returns the remainder obtained by dividing its two operands; that is,
I mod J = I - (I div J) * J
The sign of the result of mod is the same as the sign of I. A runtime error occurs if J is zero."
That is, in Delphi (1) J < 0 is allowed and (2) I mod J < 0 if I < 0.
A nasty trap if you are porting code from Delphi (or some other Pascal compilers) !
This is the result of Borland ignoring the standard. There is no excuse, because the standard was available long before the first Turbo Pascal. The drafts were published in Pascal News in the mid '70s. It is one of the reasons many will not consider Delphi/Borland/Turbo to be Pascal.
The purpose of a standard is to ensure that programs and programmers can count on the standardized behavior.