[fpc-devel] Signed division

J. Gareth Moreton gareth at moreton-family.com
Fri Jun 1 11:13:56 CEST 2018

 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180601/282cb6f3/attachment.html>

More information about the fpc-devel mailing list