[fpc-devel] Signed division
J. Gareth Moreton
gareth at moreton-family.com
Fri Jun 1 14:49:26 CEST 2018
Aah, thank you. That clears things up.
Hooray for documentation! It's the same as
suspected and listed below.
(and I noticed a mistake. I meant to say
only if the numerator (left-hand side
operand) is negative, not positive)
Gareth aka. Kit
On Fri 01/06/18 12:42 , "Christo Crause"
christo.crause at gmail.com sent:
> On Fri, Jun 1, 2018 at 11:13 AM, J.
Gareth Moreton 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 [1]
>
> Links:
> ------
> [1] https://freepascal.org/docs-
html/current/ref/refsu45.html
>
>
More information about the fpc-devel
mailing list