<div dir="ltr"><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 1, 2018 at 11:13 AM, J. Gareth Moreton <span dir="ltr"><<a href="mailto:gareth@moreton-family.com" target="_blank">gareth@moreton-family.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hi everyone,<br>
<br>
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.<br>
<br>
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.<br>
<br>
Gareth aka. Kit<br></blockquote><div><br></div><div>
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">"<span> </span></span><span style="font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium;float:none;display:inline">The sign of the result of a<span> </span></span><span class="gmail-cmtt-10" style="font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;font-family:monospace;color:rgb(0,0,0)">Mod<span> </span></span><span style="font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium;float:none;display:inline">operator is the same as the sign of the left side operand of the<span> </span></span><span class="gmail-cmtt-10" style="font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;font-family:monospace;color:rgb(0,0,0)">Mod<span> </span></span><span style="font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium;float:none;display:inline">operator</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> " - <a href="https://freepascal.org/docs-html/current/ref/refsu45.html">https://freepascal.org/docs-html/current/ref/refsu45.html</a></span>
</div></div></div></div></div>