<html><head><base href="x-msg://174/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><span class="Apple-style-span" style="font-size: medium; ">On 17 Jan 2010, at 05:50, Jay K wrote:</span></div></span></span></span></span></span></span></span></span></div></span></span></div><div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">I think I missed a sign.<br><br>-2147483648 - 2147483647  * -2<br> actually -2147483648 + 2 * 2147483647<br>  actually 2147483646<br><br>which agrees.<br><br>so<span class="Apple-converted-space"> </span><br><br>-2147483648 div 2147483647 = -2<span class="Apple-converted-space"> </span><br>-2147483648 mod 2147483647 = 2147483646<span class="Apple-converted-space"> </span><br><br>-2 * 2147483647 + 2147483646  = -2147483648<br><br>I'll make sure m3_mod works this way if it doesn't already.<br>Presumably we are stuck with these rules.<br></div></span></blockquote><div><br></div><div>Yep.  I seem to remember reading some rationale somewhere sometime somehow, but I forget where when how.  Anyone?</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; "><br> - Jay<br><br><hr id="stopSpelling">From:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Subject: integer division/mod questions?<br>Date: Sun, 17 Jan 2010 10:44:53 +0000<br><br>-2147483648 div 2147483647 ?<br>-2147483648 mod 2147483647 ?<br><br>quotient = -1, remainer = -1 seems reasonable.<br>2147483647 * -1 + -1 == -2147483648<br><br><br>However, Modula-3 specifies div as rounding down, so<br><br>-2147483648 div 2147483647  == -2<br><br>and then<br><br><a href="http://www.modula3.com/cm3/doc/reference/arithmetic.html">http://www.modula3.com/cm3/doc/reference/arithmetic.html</a><br><br>The value<span class="Apple-converted-space"> </span><tt>x DIV y</tt><span class="Apple-converted-space"> </span>is the floor of the quotient of<span class="Apple-converted-space"> </span><tt>x</tt><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span><tt>y</tt>; that is, the maximum integer not exceeding the real number<span class="Apple-converted-space"> </span><tt>z</tt><span class="Apple-converted-space"> </span>such that<span class="Apple-converted-space"> </span><tt>z * y = x</tt>. For integers<span class="Apple-converted-space"> </span><tt>x</tt><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span><tt>y</tt>, the value of<span class="Apple-converted-space"> </span><tt>x MOD y</tt><span class="Apple-converted-space"> </span>is defined to be<span class="Apple-converted-space"> </span><tt>x - y * (x DIV y)</tt>. This means that for positive<span class="Apple-converted-space"> </span><tt>y</tt>, the value of<span class="Apple-converted-space"> </span><tt>x MOD y</tt><span class="Apple-converted-space"> </span>lies in the interval<span class="Apple-converted-space"> </span><tt>[0 .. y-1]</tt>, regardless of the sign of<span class="Apple-converted-space"> </span><tt>x</tt>. For negative<span class="Apple-converted-space"> </span><tt>y</tt>, the value of<span class="Apple-converted-space"> </span><tt>x MOD y</tt><span class="Apple-converted-space"> </span>lies in the interval<span class="Apple-converted-space"> </span><tt>[y+1 .. 0]</tt>, regardless of the sign of<span class="Apple-converted-space"> </span><tt>x</tt>.<span class="Apple-converted-space"> </span><br><br>-2147483648 - 2147483647  * -2<br>-2147483648 +2  (due to overflow)<br>-2147483646<br><br>which contradicts the second part.<br><br>Maybe I'm confused? I should work this all through again?<br><br> - Jay<br></div></span></blockquote></div><br></body></html>