<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
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 <br><br>
-2147483648 div 2147483647 = -2 <br>-2147483648 mod 2147483647 = 2147483646 <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><br> - Jay<br><br><hr id="stopSpelling">From: jay.krell@cornell.edu<br>To: m3devel@elegosoft.com<br>Subject: integer division/mod questions?<br>Date: Sun, 17 Jan 2010 10:44:53 +0000<br><br>
<style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Verdana;}
</style>
-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>http://www.modula3.com/cm3/doc/reference/arithmetic.html<br><br>The value <tt>x DIV y</tt> is the floor of
the quotient of <tt>x</tt> and <tt>y</tt>; that is, the maximum integer
not exceeding the real number <tt>z</tt> such that <tt>z * y = x</tt>.
For integers <tt>x</tt> and <tt>y</tt>, the value of <tt>x MOD y</tt> is
defined to be <tt>x - y * (x DIV y)</tt>.
This means that for positive <tt>y</tt>, the value of <tt>x MOD y</tt>
lies in the interval <tt>[0 .. y-1]</tt>, regardless of
the sign of <tt>x</tt>. For negative <tt>y</tt>, the value of
<tt>x MOD y</tt> lies in the interval <tt>[y+1 .. 0]</tt>, regardless
of the sign of <tt>x</tt>.
<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> </body>
</html>