On Fri, Jun 1, 2018 at 11:13 AM, J. Gareth Moreton <
gar...@moreton-family.com> wrote:

> Hi everyone,
>
> I'm starting to make some modifications to the optimizer so it optimises
> div and mod operations on signed integers (I've done unsigned integers
> already). One question that I've stumbled across... what are the rules
> regarding the sign of the result?  Experimenting with IDIV suggests it
> returns a negative modulus only if the numerator is positive (so -28 / 3 =
> -9 remainder -1, and -28 / -3 = 9 remainder -1, but 28 / -3 = -9 remainder
> +1), which follows the Euclidean division rule of n = dq + r, where n is
> the numerator, d is the divisor, q is the resultant quotient and r is the
> resultant remainder.
>
> While I'm planning on being consistent with IDIV, what are the rules of
> signed division in Free Pascal? There are hints that some dialects of
> Pascal only return a positive modulus no matter what.
>
> Gareth aka. Kit
>

  " The sign of the result of a Mod operator is the same as the sign of the
left side operand of the Mod operator " -
https://freepascal.org/docs-html/current/ref/refsu45.html
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to